qermit.mitex¶
- class qermit.taskgraph.mitex.MitEx(backend: pytket.backends.backend.Backend, _label: str = 'MitEx', **kwargs)¶
- A TaskGraph extension for mitigation of expectation values for individual QubitPauliStrings
contained in some ObservableTracker/QubitPauliOperator.
- __call__(experiment_wires: List[List[qermit.taskgraph.mittask.ObservableExperiment]]) → Tuple[List[pytket.utils.operators.QubitPauliOperator]]¶
Call self as a function.
- __init__(backend: pytket.backends.backend.Backend, _label: str = 'MitEx', **kwargs) → None¶
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
- __str__()¶
Return str(self).
- add_n_wires(num_wires: int)¶
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()¶
Requests to add a single edge between the input vertex and output vertex. Not permitted for MitEx, raises TypeError.
- check_append_wires(task: Union[qermit.taskgraph.mittask.MitTask, qermit.taskgraph.task_graph.TaskGraph]) → bool¶
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: Union[qermit.taskgraph.mittask.MitTask, qermit.taskgraph.task_graph.TaskGraph]) → bool¶
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
- from_TaskGraph(task_graph: qermit.taskgraph.task_graph.TaskGraph)¶
Returns a MitEx object from a TaskGraph object.
- parallel(task: Union[qermit.taskgraph.mittask.MitTask, qermit.taskgraph.task_graph.TaskGraph])¶
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[qermit.taskgraph.mittask.ObservableExperiment]) → List[pytket.utils.operators.QubitPauliOperator]¶
Overloaded run method to allow type checking on input arguments and output. 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]
- mitex.gen_compiled_MitRes(optimisation_level: int = 1) → qermit.taskgraph.mitres.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.get_basic_measurement_circuit() → Tuple[pytket._tket.circuit.Circuit, Tuple[pytket._tket.pauli.QubitPauliString, List[pytket._tket.circuit.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() → qermit.taskgraph.mittask.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() → qermit.taskgraph.mittask.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.
- mitex.split_results_task_gen() → qermit.taskgraph.mittask.MitTask¶
Returned list of Results from MitRes object are for multiple experiments. This method generates a task that converts the list of results into a list of list of results, wherein each list is for a different MitEx experiment.
- mitex.get_expectations_task_gen() → qermit.taskgraph.mittask.MitTask¶
Passes each set of experiment results to corresponding ObservableTracker method, returning a QubitPauliOperator object containing expectation values from Results multiplied by coefficients.