qermit.mitex

class qermit.taskgraph.mitex.MitEx(backend, _label='MitEx', **kwargs)[source]
A TaskGraph extension for mitigation of expectation values for individual QubitPauliStrings

contained in some ObservableTracker/QubitPauliOperator.

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 – Name for identification of MitEx object.

Key mitres:

MitEx object experiments are run through

__call__(experiment_wires, cache=False, characterisation={})[source]

Call self as a function.

Return type:

Tuple[List[QubitPauliOperator]]

__init__(backend, _label='MitEx', **kwargs)[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 – Name for identification of MitEx object.

Key mitres:

MitEx object experiments are run through

__str__()[source]

Return str(self).

add_n_wires(num_wires)[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)[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.

Return type:

bool

Returns:

True if task is suitably for appending, False if not.

check_prepend_wires(task)[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.

Return type:

bool

Returns:

True if task is suitably for prepending, False if not.

from_TaskGraph(task_graph)[source]

Returns a MitEx object from a TaskGraph object.

Parameters:

task_graph (TaskGraph) – TaskGraph object to copy tasks from.

Returns:

Copied TaskGraph as MitEx

parallel(task)[source]

Requests to add new MitTask/TaskGraph to TaskGraph object in parallel. Not permitted for MitEx, raises TypeError.

Parameters:

task (Union[MitTask, TaskGraph]) – New task to be added in parallel.

run(mitex_wires, cache=False, characterisation={})[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.

Return type:

List[QubitPauliOperator]

Returns:

Observable experiment results as QubitPauliOperator, where values are expectations.

run_basic(mitex_wires)[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.

Return type:

List[QubitPauliOperator]

Returns:

Observable experiment results as QubitPauliOperator, where values are expectations.

qermit.taskgraph.mitex.gen_compiled_MitRes(backend, optimisation_level=1)[source]

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

Return type:

MitRes

Returns:

MitRes object with compilation task prepended.

qermit.taskgraph.mitex.gen_compiled_shot_split_MitRes(backend, max_shots, optimisation_level=1)[source]

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

Return type:

MitRes

Returns:

shot splitting MitRes object with compilation task prepended.

qermit.taskgraph.mitex.get_basic_measurement_circuit(string)[source]

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

Return type:

Tuple[Circuit, Tuple[QubitPauliString, List[Bit], bool]]

Returns:

Measurement circuit for appending on some ansatz

qermit.taskgraph.mitex.filter_observable_tracker_task_gen()[source]

Generates basic (changing measurement basis via Pauli gates) MeasurementCircuit for every QubitPauliString passed that has no Measurementcircuit in ObservableTracker object passed on wire.

Return type:

MitTask

Returns:

Pure function that adds MeasurementCircuit objects to ObservableTracker.

qermit.taskgraph.mitex.collate_circuit_shots_task_gen()[source]

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.

Return type:

MitTask

qermit.taskgraph.mitex.split_results_task_gen()[source]

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.

Return type:

MitTask

qermit.taskgraph.mitex.get_expectations_task_gen()[source]

Passes each set of experiment results to corresponding ObservableTracker method, returning a QubitPauliOperator object containing expectation values from Results multiplied by coefficients.

Return type:

MitTask