qermit.mitres

class qermit.taskgraph.mitres.MitRes(backend, _label='MitRes')[source]

A TaskGraph extension of mitigation of counts/shots for individual circuits.

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

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

Call self as a function.

Return type:

Tuple[List[BackendResult]]

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

__str__()[source]

Return str(self).

Return type:

str

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 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)[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.

Return type:

bool

Returns:

True if task is suitable for apppending, 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[CircuitShots] and that its return type is Tuple[List[CircuitShots]].

Parameters:

task (Union[MitTask, TaskGraph]) – MitTask or TaskGraph object for checking wire numbers of.

Return type:

bool

Returns:

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

from_TaskGraph(task_graph)[source]

Returns a MitRes object from a TaskGraph object.

Parameters:

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

Returns:

Copied TaskGraph as MitRes

parallel(task)[source]

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

Parameters:

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

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

Return type:

List[BackendResult]

Returns:

A BackendResult object for each combination of circuit and shots.

qermit.taskgraph.mitres.backend_compile_circuit_shots_task_gen(backend, optimisation_level=1)[source]

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 (int) – Optimisation level of backend called.

Return type:

MitTask

qermit.taskgraph.mitres.backend_handle_task_gen(backend)[source]

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.

Return type:

MitTask

Returns:

Pure function that adds passes circuits to backend and gets handles.

qermit.taskgraph.mitres.backend_res_task_gen(backend)[source]

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.

Return type:

MitTask

qermit.taskgraph.mitres.gen_shot_split_MitRes(backend, max_shots)[source]

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.

Return type:

MitRes

Returns:

A MitRes object.

qermit.taskgraph.mitres.split_shots_task_gen(max_shots)[source]

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.

Return type:

MitTask

Returns:

A task dividing the job into several smaller ones.

qermit.taskgraph.mitres.group_shots_task_gen()[source]

Returns task which groups together jobs that correspond to the same circuit. Original larger job could have been split by task returned by split_shots_task_gen.

Return type:

MitTask

Returns:

Task merging jobs which correspond to the same circuit.