Skip to main contentIBM Quantum Documentation
You are viewing the API reference for an old version of Qiskit SDK. Switch to latest version

QuantumInstance

class qiskit.utils.QuantumInstance(backend, shots=None, seed_simulator=None, basis_gates=None, coupling_map=None, initial_layout=None, pass_manager=None, bound_pass_manager=None, seed_transpiler=None, optimization_level=None, backend_options=None, noise_model=None, timeout=None, wait=5.0, skip_qobj_validation=True, measurement_error_mitigation_cls=None, cals_matrix_refresh_period=30, measurement_error_mitigation_shots=None, job_callback=None, mit_pattern=None, max_job_retries=50)

GitHub(opens in a new tab)

Bases: object(opens in a new tab)

Deprecated: Quantum Backend including execution setting.

Quantum Instance holds a Qiskit Terra backend as well as configuration for circuit transpilation and execution. When provided to an Aqua algorithm the algorithm will execute the circuits it needs to run using the instance.

Deprecated since version 0.24.0

The class qiskit.utils.quantum_instance.QuantumInstance is deprecated as of qiskit-terra 0.24.0. It will be removed in the Qiskit 1.0 release. For code migration guidelines, visit https://qisk.it/qi_migration(opens in a new tab).

Parameters

  • backend (Backend) – Instance of selected backend
  • shots (int(opens in a new tab) | None) – Number of repetitions of each circuit, for sampling. If None, the shots are extracted from the backend. If the backend has none set, the default is 1024.
  • seed_simulator (int(opens in a new tab) | None) – Random seed for simulators
  • basis_gates (List(opens in a new tab)[str(opens in a new tab)] | None) – List of basis gate names supported by the target. Defaults to basis gates of the backend.
  • coupling_map (Optional[Union['CouplingMap', List[List]]]) – Coupling map (perhaps custom) to target in mapping
  • initial_layout (Optional[Union['Layout', Dict, List]]) – Initial layout of qubits in mapping
  • pass_manager (Optional['PassManager']) – Pass manager to handle how to compile the circuits. To run only this pass manager and not the bound_pass_manager, call the transpile() method with the argument pass_manager=quantum_instance.unbound_pass_manager.
  • bound_pass_manager (Optional['PassManager']) – A second pass manager to apply on bound circuits only, that is, circuits without any free parameters. To only run this pass manager and not pass_manager call the transpile() method with the argument pass_manager=quantum_instance.bound_pass_manager. manager should also be run.
  • seed_transpiler (int(opens in a new tab) | None) – The random seed for circuit mapper
  • optimization_level (int(opens in a new tab) | None) – How much optimization to perform on the circuits. Higher levels generate more optimized circuits, at the expense of longer transpilation time.
  • backend_options (Dict(opens in a new tab) | None) – All running options for backend, please refer to the provider of the backend for information as to what options it supports.
  • noise_model (Optional['NoiseModel']) – noise model for simulator
  • timeout (float(opens in a new tab) | None) – Seconds to wait for job. If None, wait indefinitely.
  • wait (float(opens in a new tab)) – Seconds between queries for job result
  • skip_qobj_validation (bool(opens in a new tab)) – Bypass Qobj validation to decrease circuit processing time during submission to backend.
  • measurement_error_mitigation_cls (Callable(opens in a new tab) | None) – The approach to mitigate measurement errors. The classes CompleteMeasFitter or TensoredMeasFitter from the qiskit.utils.mitigation module can be used here as exact values, not instances. TensoredMeasFitter doesn’t support the subset_fitter method.
  • cals_matrix_refresh_period (int(opens in a new tab)) – How often to refresh the calibration matrix in measurement mitigation. in minutes
  • measurement_error_mitigation_shots (int(opens in a new tab) | None) – The number of shots number for building calibration matrix. If None, the main shots parameter value is used.
  • job_callback (Callable(opens in a new tab) | None) – Optional user supplied callback which can be used to monitor job progress as jobs are submitted for processing by an Aqua algorithm. The callback is provided the following arguments: job_id, job_status, queue_position, job
  • mit_pattern (List(opens in a new tab)[List(opens in a new tab)[int(opens in a new tab)]] | None) – Qubits on which to perform the TensoredMeasFitter measurement correction, divided to groups according to tensors. If None and qr is given then assumed to be performed over the entire qr as one group (default None).
  • max_job_retries (int(opens in a new tab)) – positive non-zero number of trials for the job set (-1 for infinite trials) (default: 50)

Raises

  • QiskitError – the shots exceeds the maximum number of shots
  • QiskitError – set noise model but the backend does not support that
  • QiskitError – set backend_options but the backend does not support that

Attributes

backend

Return Backend backend object.

backend_config

Getter of backend_config.

backend_name

Return backend name.

backend_options

Getter of backend_options.

bound_pass_manager

Return the pass manager for designated for bound circuits.

Returns

The pass manager for bound circuits, if it has been set.

Return type

Optional[‘PassManager’]

cals_matrix_refresh_period

returns matrix refresh period

circuit_summary

Getter of circuit summary.

compile_config

Getter of compile_config.

is_local

Return True if backend is a local backend.

is_simulator

Return True if backend is a simulator.

is_statevector

Return True if backend is a statevector-type simulator.

max_job_retries

Getter of max tries

measurement_error_mitigation_cls

returns measurement error mitigation cls

measurement_error_mitigation_shots

returns measurement error mitigation shots

noise_config

Getter of noise_config.

qjob_config

Getter of qjob_config.

run_config

Getter of run_config.

skip_qobj_validation

checks if skip qobj validation

time_taken

Accumulated time taken for execution.

unbound_pass_manager

Return the pass manager for designated for unbound circuits.

Returns

The pass manager for unbound circuits, if it has been set.

Return type

Optional[‘PassManager’]


Methods

assemble

assemble(circuits)

assemble circuits

Return type

QasmQobj | PulseQobj

cals_matrix

cals_matrix(qubit_index=None)

Get the stored calibration matrices and its timestamp.

Parameters

qubit_index (List(opens in a new tab)[int(opens in a new tab)] | None) – the qubit index of corresponding calibration matrix. If None, return all stored calibration matrices.

Returns

The calibration matrix and the creation timestamp if qubit_index is not None otherwise, return all matrices and their timestamp in a dictionary.

Return type

Tuple(opens in a new tab)[ndarray(opens in a new tab), float(opens in a new tab)] | Dict(opens in a new tab)[str(opens in a new tab), Tuple(opens in a new tab)[ndarray(opens in a new tab), float(opens in a new tab)]] | None

execute

execute(circuits, had_transpiled=False)

A wrapper to interface with quantum backend.

Parameters

  • circuits (Union['QuantumCircuit', List['QuantumCircuit']]) – circuits to execute
  • had_transpiled (bool(opens in a new tab)) – whether or not circuits had been transpiled

Raises

Returns

result object

Return type

Result

TODO: Maybe we can combine the circuits for the main ones and calibration circuits before

assembling to the qobj.

maybe_refresh_cals_matrix

maybe_refresh_cals_matrix(timestamp=None)

Calculate the time difference from the query of last time.

Parameters

timestamp (float(opens in a new tab) | None) – timestamp

Returns

Whether or not refresh the cals_matrix

Return type

bool(opens in a new tab)

reset_execution_results

reset_execution_results()

Reset execution results

set_config

set_config(**kwargs)

Set configurations for the quantum instance.

transpile

transpile(circuits, pass_manager=None)

A wrapper to transpile circuits to allow algorithm access the transpiled circuits.

Parameters

  • circuits (Union['QuantumCircuit', List['QuantumCircuit']]) – circuits to transpile
  • pass_manager (Optional['PassManager']) – A pass manager to transpile the circuits. If none is given, but either pass_manager or bound_pass_manager has been set in the initializer, these are run. If none has been provided there either, the backend and compile configs from the initializer are used.

Returns

The transpiled circuits, it is always a list even though

the length is one.

Return type

List[‘QuantumCircuit’]

Was this page helpful?
Report a bug or request content on GitHub.