qermit.mitex#
- class qermit.taskgraph.mitex.MitEx(backend: Backend, _label: str = 'MitEx', **kwargs)[source]#
- A TaskGraph extension for mitigation of expectation values for individual QubitPauliStrings
contained in some ObservableTracker/QubitPauliOperator.
- __call__(experiment_wires: List[List[ObservableExperiment]], cache: bool = False, characterisation: dict = {}) Tuple[List[QubitPauliOperator]] [source]#
Call self as a function.
- __init__(backend: Backend, _label: str = 'MitEx', **kwargs) None [source]#
MitEx objects are defined by the backend object experiments are run through. However, as experiments run through some MitRes object, kwargs can be used to run through any mitres of choice.
- Parameters:
backend (Backend) – Pytket backend default constructor which tasks are generated from.
label (str) – Name for identification of MitEx object.
- Key mitres:
MitEx object experiments are run through
- add_n_wires(num_wires: int)[source]#
Requests to add num_wires number of edges between the input vertex and output vertex, with no type restrictions. Not permitted for MitEx, raises TypeError.
- Parameters:
num_wires (int) – Number of edges to add between input and output vertices.
- add_wire()[source]#
Requests to add a single edge between the input vertex and output vertex. Not permitted for MitEx, raises TypeError.
- check_append_wires(task: MitTask | TaskGraph) bool [source]#
Confirms that the number of in wires the passed task has is equal to the number of in wires to the output, and that the number of out wires the passed task has is 1. Also checks that the task.run attribute argument is List[QubitPauliOperator] and that its return type is Tuple[List[QubitPauliOperator]].
- Parameters:
task (Union[MitTask, Taskgraph]) – MitTask or TaskGraph object for checking wire numbers of.
- Returns:
True if task is suitably for appending, False if not.
- Return type:
bool
- check_prepend_wires(task: MitTask | TaskGraph) bool [source]#
Confirms that the number of out wires the passed task has is equal to the number of out wires from the input, and that the number of in wires the passed task has is 1. Also checks that the task.run attribute argument is List[ObservableExperiment] and that its return type is Tuple[List[ObservableExperiment]].
- Parameters:
task (Union[MitTask, Taskgraph]) – MitTask or TaskGraph object for checking wire numbers of.
- Returns:
True if task is suitably for prepending, False if not.
- Return type:
bool
- parallel(task: MitTask | TaskGraph)[source]#
Requests to add new MitTask/TaskGraph to TaskGraph object in parallel. Not permitted for MitEx, raises TypeError.
- Parameters:
task (MitTask) – New task to be added in parallel.
- run(mitex_wires: List[ObservableExperiment], cache: bool = False, characterisation: dict = {}) List[QubitPauliOperator] [source]#
Overloaded run method. A single observable experiment is defined by a Tuple containg an Ansatz Circuit object and an ObservableTracker object. An AnsatzCircuit is a tuple containing a Circuit without measures (the ansatz circuit), the number of shots to be taken of each Measurement Circuit later run and a SymbolsDict object holding a dictionary between Circuit Symbolics (if present) and values for substituting them with when running measurement circuits (i.e. parameters). It is useful to keep parameters as symbolics until measurement circuits are executed as some mitigation methods benefit from being able to run differently parameterised circuits. An ObservableTracker object is defined by a QubitPauliOperator defining the observable of interest (a dictionary between QubitPauliStrings and coefficients), and later stores MeasurementCircuit objects for running on devices.
- Parameters:
mitex_wires (List[ObservableExperiment]) – Each Tuple pertains to a different Observable measuring experiment, and contains the minimum amount of information to run an Mitigated Experiment for calculating observables.
- Returns:
Observable experiment results as QubitPauliOperator, where values are expectations.
- Return type:
List[QubitPauliOperator]
- run_basic(mitex_wires: List[Tuple[CircuitShots, QubitPauliOperator]]) List[QubitPauliOperator] [source]#
Additional run option for MitEx which simplifies the arguments required for basic experiments. An experiment is defined here as just the ansatz circuit, number of shots and the operator being measured. This method converts these into the arguments for using run, calls run and then returns the desired operator.
- Parameters:
mitex_wires (List[Tuple[CircuitShots, QubitPauliOperator]]) – Each tuple pertains to a different basic observable measuring experiment.
- Returns:
Observable experiment results as QubitPauliOperator, where values are expectations.
- Return type:
List[QubitPauliOperator]
- mitex.gen_compiled_MitRes(optimisation_level: int = 1) MitRes #
Returns a MitRes object with a compilation task prepended that compiles circuit wires via backend.compile_circuit. Optimisaion level can be optionally set as defined by backend.compile_circuit.
- Parameters:
backend (Backend) – Backend with circuits are compiled for.
optimisation_level (int) – Sets options in compile_circuit method
- Returns:
MitRes object with compilation task prepended.
- Return type:
- mitex.gen_compiled_shot_split_MitRes(max_shots: int, optimisation_level: int = 1) MitRes #
Returns a shot splitting MitRes object with a compilation task prepended that compiles circuit wires via backend.compile_circuit. Optimisation level can be optionally set as defined by backend.compile_circuit.
- Parameters:
backend (Backend) – Backend with circuits are compiled for.
max_shots (int) – The maximum number of shots that each job should request.
optimisation_level (int) – Sets options in compile_circuit method
- Returns:
shot splitting MitRes object with compilation task prepended.
- Return type:
- mitex.get_basic_measurement_circuit() Tuple[Circuit, Tuple[QubitPauliString, List[Bit], bool]] #
Given a Qubit Pauli String, returns a circuit for measuring qubits in given basis via changing of basis through quantum gates.
- Parameters:
string (QubitPauliString) – Qubit Pauli String to be measured
- Returns:
Measurement circuit for appending on some ansatz
- Return type:
Circuit
- mitex.filter_observable_tracker_task_gen() MitTask #
Generates basic (changing measurement basis via Pauli gates) MeasurementCircuit for every QubitPauliString passed that has no Measurementcircuit in ObservableTracker object passed on wire.
- Returns:
Pure function that adds MeasurementCircuit objects to ObservableTracker.
- Return type:
- mitex.collate_circuit_shots_task_gen() MitTask #
Each wire contains a single experiment with its own List of Circuits to run. To improve parallelisation (i.e. reduce queueing time), these lists are collated and queued for a device at the same time.