pygsti.extras.ibmq.ibmqexperiment.IBMQExperiment#

class IBMQExperiment(edesign, pspec, remove_duplicates=True, randomized_order=True, circuits_per_batch=75, num_shots=1024, seed=None, checkpoint_path=None, disable_checkpointing=False, checkpoint_override=False)#

Bases: TreeNode, HasProcessorSpec

A object that converts pyGSTi ExperimentDesigns into jobs to be submitted to IBM Q, submits these jobs to IBM Q and receives the results.

Methods

__init__(edesign, pspec[, ...])

create_target_model(**kwargs)

from_dir(dirname[, regen_jobs, service, ...])

Initialize a new IBMQExperiment object from dirname.

items()

An iterator over the (child_name, child_node) pairs of this node.

keys()

An iterator over the keys (child names) of this tree node.

monitor()

Queries IBM Q for the status of the jobs.

prune_tree(paths[, paths_are_sorted])

Prune the tree rooted here to include only the given paths, discarding all other leaves & branches.

retrieve_results()

Gets the results of the completed jobs from IBM Q, and processes them into a pyGSTi DataProtocol object (stored as the key 'data'), which can then be used in pyGSTi data analysis routines (e.g., if this was a GST experiment, it can input into a GST protocol object that will analyze the data).

submit(ibmq_backend[, start, stop, ...])

Submits the jobs to IBM Q, that implements the experiment specified by the ExperimentDesign used to create this object.

transpile(ibmq_backend[, direct_to_qiskit, ...])

Transpile pyGSTi circuits into Qiskit circuits for submission to IBMQ.

underlying_tree_paths()

Dictionary paths leading to data objects/nodes beneath this one.

view(keys_to_keep)

Get a "view" of this tree node that only has a subset of this node's children.

write([dirname])

Writes to disk, storing both the pyGSTi ProtocolData object in pyGSTi's standard format and saving all of the IBM Q submission information stored in this object, written into the subdirectory 'ibmqexperiment'.

classmethod from_dir(dirname, regen_jobs=False, service=None, new_checkpoint_path=None)#

Initialize a new IBMQExperiment object from dirname.

Parameters:
  • dirname (str) – The directory name.

  • regen_jobs (bool, optional) – Whether to recreate the RuntimeJobs from IBMQ based on the job ides. Defaults to False. You should set this to True if you would like to call monitor() or retrieve_results().

  • service (QiskitRuntimeService) – Service used to retrieve RuntimeJobs from IBMQ based on job_ids (if regen_jobs is True).

  • new_checkpoint_path (str, optional) – A string for the path to use for writing intermediate checkpoint files to disk. If None, this defaults to using the same checkpoint as the serialized IBMQExperiment object. If provided, this will be the new checkpoint path used moving forward. Note that this can be the desired {dirname} for an eventual write({dirname}) call, i.e. the serialized IBMQExperiment checkpoint after a successful retrieve_results() is equivalent to the serialized IBMQExperiment after write().

Return type:

IBMQExperiment

items()#

An iterator over the (child_name, child_node) pairs of this node.

keys()#

An iterator over the keys (child names) of this tree node.

monitor()#

Queries IBM Q for the status of the jobs.

prune_tree(paths, paths_are_sorted=False)#

Prune the tree rooted here to include only the given paths, discarding all other leaves & branches.

Parameters:
  • paths (list) – A list of tuples specifying the paths to keep.

  • paths_are_sorted (bool, optional) – Whether paths is sorted (lexicographically). Setting this to True will save a little time.

Returns:

A view of this node and its descendants where unwanted children have been removed.

Return type:

TreeNode

retrieve_results()#

Gets the results of the completed jobs from IBM Q, and processes them into a pyGSTi DataProtocol object (stored as the key ‘data’), which can then be used in pyGSTi data analysis routines (e.g., if this was a GST experiment, it can input into a GST protocol object that will analyze the data).

submit(ibmq_backend, start=None, stop=None, ignore_job_limit=True, wait_time=5, max_attempts=10, ibmq_session=None)#

Submits the jobs to IBM Q, that implements the experiment specified by the ExperimentDesign used to create this object.

Parameters:
  • ibmq_backend (qiskit.providers.ibmq.ibmqbackend.IBMQBackend or qiskit_aer.AerSimulator) – The IBM Q backend to submit the jobs to. Should be the backend corresponding to the processor that this experiment has been designed for.

  • start (int, optional) – Batch index to start submission (inclusive). Defaults to None, which will start submission on the first unsubmitted job. Jobs can be resubmitted by manually specifying this, i.e. start=0 will start resubmitting jobs from the beginning.

  • stop (int, optional) – Batch index to stop submission (exclusive). Defaults to None, which will submit as many jobs as possible given the backend’s maximum job limit.

  • ignore_job_limit (bool, optional) – If True, then stop is set to submit all remaining jobs. This is set as True to maintain backwards compatibility. Note that is more jobs are needed than the max limit, this will enter a wait loop until all jobs have been successfully submitted.

  • wait_time (int) – Number of seconds for each waiting step.

  • wait_steps (int) – Number of steps to take before retrying job submission.

  • ibmq_session (IBMQuantumRuntimeSession) – IBMQuantumRuntime Session to use

Return type:

None

transpile(ibmq_backend, direct_to_qiskit=False, qiskit_pass_kwargs=None, qasm_convert_kwargs=None, qiskit_convert_kwargs=None, num_workers=1, use_ibm_mcm=True)#

Transpile pyGSTi circuits into Qiskit circuits for submission to IBMQ.

Parameters:
  • ibmq_backend – IBM backend to use during Qiskit transpilation

  • direct_to_qiskit (bool, optional) – Whether to use OpenQASM as an intermediary in the conversion from pyGSTi circut to Qiskit circuit. If True, qiskit_convert_kwargs is passed to Circuit.convert_to_qiskit. If False, the pyGSTi circuits are first converted to OpenQASM and then converted into Qiskit circuits.

  • qiskit_pass_kwargs (dict, optional) – Only used if direct_to_qiskit is False. Additional kwargs to pass in to generate_preset_pass_manager. If not defined, the default is {‘seed_transpiler’: self.seed, ‘optimization_level’: 0, ‘basis_gates’: ibmq_backend.operation_names} Note that “optimization_level” is a required argument to the pass manager.

  • qasm_convert_kwargs (dict, optional) – Only used if direct_to_qiskit is False. Additional kwargs to pass in to Circuit.convert_to_openqasm. If not defined, the default is {‘num_qubits’: self.processor_spec.num_qubits, ‘standard_gates_version’: ‘x-sx-rz’}

  • qiskit_convert_kwargs (dict, optional) – Only used if direct_to_qiskit is True. Additional kwargs to pass to Circuit.convert_to_qiskit. If not defined, the default is {‘num_qubits’: self.processor_spec.num_qubits, ‘qubit_conversion’: ‘remove-Q’, ‘block_between_layers’: True, ‘qubits_to_measure’: ‘active’}.

  • num_workers (int, optional) – Number of workers to use for parallel (by batch) transpilation

underlying_tree_paths()#

Dictionary paths leading to data objects/nodes beneath this one.

Returns:

A list of tuples, each specifying the tree traversal to a child node. The first tuple is the empty tuple, referring to this (root) node.

Return type:

list

view(keys_to_keep)#

Get a “view” of this tree node that only has a subset of this node’s children.

Parameters:

keys_to_keep (iterable) – A sequence of key names to keep.

Return type:

TreeNode

write(dirname=None)#

Writes to disk, storing both the pyGSTi ProtocolData object in pyGSTi’s standard format and saving all of the IBM Q submission information stored in this object, written into the subdirectory ‘ibmqexperiment’.

Parameters:

dirname (str) – The root directory to write into. This directory will have an ‘edesign’ subdirectory, which will be created if needed and overwritten if present. If None, then the path this object was loaded from is used (if this object wasn’t loaded from disk, an error is raised).