qermit.mitres#
- class qermit.taskgraph.mitres.MitRes(backend: Backend, _label: str = 'MitRes')[source]#
A TaskGraph extension of mitigation of counts/shots for individual circuits.
- __call__(circuits_wire: List[List[CircuitShots]], cache: bool = False, characterisation: dict = {}) Tuple[List[BackendResult]] [source]#
Call self as a function.
- __init__(backend: Backend, _label: str = 'MitRes') None [source]#
MitRes objects are defined by the backend objects all circuits are executed on.
- Parameters:
backend (Backend) – Pytket backend default constructor which tasks are generated from.
label (str) – Name for identification of MitRes object.
- 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 MitRes, 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 MitRes, 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[BackendResult] and that its return type is Tuple[List[BackendResult]].
- Parameters:
task (Union[MitTask, Taskgraph]) – MitTask or TaskGraph object for checking wire numbers of.
- Returns:
True if task is suitable for apppending, 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[CircuitShots] and that its return type is Tuple[List[CircuitShots]].
- Parameters:
task (Union[MitTask, Taskgraph]) – MitTask or TaskGraph object for checking wire numbers of.
- Returns:
True if task is suitable 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 MitRes, raises TypeError.
- Parameters:
task (MitTask) – New task to be added in parallel.
- run(circuit_shots: List[CircuitShots], cache: bool = False, characterisation: dict = {}) List[BackendResult] [source]#
Overloaded run method from TaskGraph class to add type checking. A single experiment is defined by a Tuple containing a circuit to be run on some backend and the number of shots to take of said circuit. For each combination of Circuit and shots run returns a BackendResult object containing counts/shots.
- Parameters:
circuit_shotss – Each tuple in circuit_wires contains a Circuit to run on internal backends and the number of shots to take of said circuit.
- Returns:
A BackendResult object for each combination of circuit and shots.
- Return type:
List[BackendResult]
- mitres.backend_compile_circuit_shots_task_gen(optimisation_level: int = 1) MitTask #
For each circuit in passed List[CircuitShots] argument, pass circuit to compile_circuit method of given backend with given optimisation level. Returns new wire wherein each circuit has been compiled.
- Parameters:
backend (Backend) – Backend object from which compile circuit method is called
optimisation_level – Optimisation level of backend called.
- mitres.backend_handle_task_gen() MitTask #
Passes every tuple of Circuit and Shots to the backend object MitTask is defined by, returning a handle for later retrieving results for each circuit. If different numbers of shots are passed, each circuit is run with the maximum number of shots.
- Parameters:
backend (Backend) – Backend circuits are run through.
- Returns:
Pure function that adds passes circuits to backend and gets handles.
- Return type:
- mitres.backend_res_task_gen() MitTask #
For each ResultHandle passed to task, retrieves a BackendResult object from the backend the task is defined by.
- Parameters:
backend (Backend) – backend holding results for handles.
- mitres.gen_shot_split_MitRes(max_shots: int) MitRes #
Wraps a mitres in tasks which ensures shots requested by individual jobs never exceed max_shots. It does so by splitting the shots over several jobs if necessary.
- Parameters:
backend (Backend) – The backend on which to run the jobs.
max_shots (int) – The maximum number of shots that each job should request.
- Returns:
A MitRes object.
- Return type:
- mitres.split_shots_task_gen() MitTask #
When the number of shots requested is higher than max_shots, this task splits the jobs into several individual jobs, where the total number of shots matches that initially requested.
- Parameters:
max_shots (int) – The maximum number of shots per job.
- Returns:
A task dividing the job into several smaller ones.
- Return type: