tensorcircuit.results.qem.qem_methods#

quantum error mitigation functionalities

tensorcircuit.results.qem.qem_methods.add_dd(c: Any, rule: Callable[[int], Any]) Any[source]#

Add DD sequence to A circuit

Parameters
  • c (Any) – circuit

  • rule (Callable[[int], Any]) – The rule to conduct the DD sequence

Returns

new circuit

Return type

Any

tensorcircuit.results.qem.qem_methods.apply_dd(circuit: Any, executor: Callable[[Any], Any], rule: Union[Callable[[int], Any], List[str]], rule_args: Optional[Dict[str, Any]] = None, num_trials: int = 1, full_output: bool = False, ignore_idle_qubit: bool = True, fulldd: bool = False, iscount: bool = False) Union[float, Tuple[float, List[Any]], Dict[str, float], Tuple[Dict[str, float], List[Any]]][source]#

Apply dynamic decoupling (DD) and return the mitigated results.

Parameters
  • circuit (Any) – The aim circuit.

  • executor (Callable[[Any], Any]) – A executor that executes a circuit and return results.

  • rule – The rule to construct DD sequence, can use default rule “dd_option.rules.xx”

or custom rule “[‘X’,’X’]” :type rule: Union[Callable[[int], Any], List[str]] :param rule_args:An optional dictionary of keyword arguments for rule, defaults to {}. :type rule_args: Dict[str, Any], optional :param num_trials: The number of independent experiments to average over, defaults to 1 :type num_trials: int, optional :param full_output: If False only the mitigated expectation value is

returned. If True a dictionary containing all DD data is returned too, defaults to False

Parameters
  • ig_idle_qubit (bool, optional) – ignore the DD sequences that added to unused qubits, defaults to True

  • fulldd (bool, optional) – dd sequence full fill the idle circuits, defaults to False

  • iscount (bool, optional) – whether the output is bit string, defaults to False

Returns

mitigated expectation value or mitigated expectation value and DD circuit information

Return type

Union[float, Tuple[float, Dict[str, Any]]]

tensorcircuit.results.qem.qem_methods.apply_rc(circuit: Any, executor: Callable[[Any], Any], num_to_average: int = 1, simplify: bool = True, iscount: bool = False, **kws: Any) Tuple[float, List[Any]][source]#

Apply Randomized Compiling or Pauli twirling on two-qubit gates.

Parameters
  • circuit (Any) – Input circuit

  • executor (Callable[[Any], Any]) – A executor that executes a circuit and return results.

  • num_to_average (int, optional) – Number of circuits for RC, defaults to 1

  • simplify (bool, optional) – Whether simplify the circuits by merging single qubit gates, defaults to True

  • iscount (bool, optional) – whether the output is bit string, defaults to False

Returns

Mitigated results by RC

Return type

float

tensorcircuit.results.qem.qem_methods.apply_zne(circuit: Any, executor: Callable[[Union[Any, Sequence[Any]]], Any], factory: Optional[Any], scale_noise: Optional[Callable[[Any, float], Any]] = None, num_to_average: int = 1, **kws: Any) Any[source]#

Apply zero-noise extrapolation (ZNE) and return the mitigated results.

Parameters
  • circuit (Any) – The aim circuit.

  • executor (Callable[[Union[Any, Sequence[Any]]], Any]) – A executor that executes a single circuit or a batch of circuits and return results.

  • factory (Optional[Factory]) – Determines the extropolation method.

  • scale_noise (Callable[[Any, float], Any], optional) – The scaling function for the aim circuit, defaults to fold_gates_at_random

  • num_to_average (int, optional) – Number of times expectation values are computed by the executor, average each point, defaults to 1.

Returns

Mitigated average value by ZNE.

Return type

float

tensorcircuit.results.qem.qem_methods.prune_ddcircuit(c: Any, qlist: List[int]) Any[source]#

Discard DD sequence on idle qubits and Discard identity gate (no identity/idle gate on device now) filled in DD sequence.

Parameters
  • c (Any) – circuit

  • qlist (list) – qubit list to apply DD sequence

Returns

new circuit

Return type

Any

tensorcircuit.results.qem.qem_methods.rc_candidates(gate: tensorcircuit.gates.Gate) List[Any][source]#
tensorcircuit.results.qem.qem_methods.rc_circuit(c: Any) Any[source]#
tensorcircuit.results.qem.qem_methods.used_qubits(c: Any) List[int][source]#

Create a qubit list that includes all qubits having gate manipulation.

Parameters

c (Any) – a circuit

Returns

qubit list

Return type

List