qiskit.aqua.QuantumInstance
class QuantumInstance(backend, shots=1024, seed_simulator=None, max_credits=10, basis_gates=None, coupling_map=None, initial_layout=None, 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)
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.
Parameters
- backend (
BaseBackend
) – Instance of selected backend - shots (
int
) – Number of repetitions of each circuit, for sampling - seed_simulator (
Optional
[int
]) – Random seed for simulators - max_credits (
int
) – Maximum credits to use - basis_gates (
Optional
[List
[str
]]) – List of basis gate names supported by the target. Defaults to basis gates of the backend. - coupling_map (
Union
[CouplingMap
,List
[List
],None
]) – Coupling map (perhaps custom) to target in mapping - initial_layout (
Union
[Layout
,Dict
,List
,None
]) – Initial layout of qubits in mapping - pass_manager (
Optional
[PassManager
]) – Pass manager to handle how to compile the circuits - seed_transpiler (
Optional
[int
]) – The random seed for circuit mapper - optimization_level (
Optional
[int
]) – How much optimization to perform on the circuits. Higher levels generate more optimized circuits, at the expense of longer transpilation time. - backend_options (
Optional
[Dict
]) – 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 (
Optional
[float
]) – Seconds to wait for job. If None, wait indefinitely. - wait (
float
) – Seconds between queries for job result - skip_qobj_validation (
bool
) – Bypass Qobj validation to decrease circuit processing time during submission to backend. - measurement_error_mitigation_cls (
Optional
[Callable
]) – The approach to mitigate measurement errors. Qiskit Ignis provides fitter classes for this functionality and CompleteMeasFitter from qiskit.ignis.mitigation.measurement module can be used here. (TensoredMeasFitter is not supported). - cals_matrix_refresh_period (
int
) – How often to refresh the calibration matrix in measurement mitigation. in minutes - measurement_error_mitigation_shots (
Optional
[int
]) – The number of shots number for building calibration matrix. If None, the main shots parameter value is used. - job_callback (
Optional
[Callable
]) – 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
Raises
- AquaError – the shots exceeds the maximum number of shots
- AquaError – set noise model but the backend does not support that
- AquaError – set backend_options but the backend does not support that
__init__
__init__(backend, shots=1024, seed_simulator=None, max_credits=10, basis_gates=None, coupling_map=None, initial_layout=None, 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)
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.
Parameters
- backend (
BaseBackend
) – Instance of selected backend - shots (
int
) – Number of repetitions of each circuit, for sampling - seed_simulator (
Optional
[int
]) – Random seed for simulators - max_credits (
int
) – Maximum credits to use - basis_gates (
Optional
[List
[str
]]) – List of basis gate names supported by the target. Defaults to basis gates of the backend. - coupling_map (
Union
[CouplingMap
,List
[List
],None
]) – Coupling map (perhaps custom) to target in mapping - initial_layout (
Union
[Layout
,Dict
,List
,None
]) – Initial layout of qubits in mapping - pass_manager (
Optional
[PassManager
]) – Pass manager to handle how to compile the circuits - seed_transpiler (
Optional
[int
]) – The random seed for circuit mapper - optimization_level (
Optional
[int
]) – How much optimization to perform on the circuits. Higher levels generate more optimized circuits, at the expense of longer transpilation time. - backend_options (
Optional
[Dict
]) – 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 (
Optional
[float
]) – Seconds to wait for job. If None, wait indefinitely. - wait (
float
) – Seconds between queries for job result - skip_qobj_validation (
bool
) – Bypass Qobj validation to decrease circuit processing time during submission to backend. - measurement_error_mitigation_cls (
Optional
[Callable
]) – The approach to mitigate measurement errors. Qiskit Ignis provides fitter classes for this functionality and CompleteMeasFitter from qiskit.ignis.mitigation.measurement module can be used here. (TensoredMeasFitter is not supported). - cals_matrix_refresh_period (
int
) – How often to refresh the calibration matrix in measurement mitigation. in minutes - measurement_error_mitigation_shots (
Optional
[int
]) – The number of shots number for building calibration matrix. If None, the main shots parameter value is used. - job_callback (
Optional
[Callable
]) – 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
Raises
Methods
__init__ (backend[, shots, seed_simulator, …]) | Quantum Instance holds a Qiskit Terra backend as well as configuration for circuit transpilation and execution. |
assemble (circuits) | assemble circuits |
cals_matrix ([qubit_index]) | Get the stored calibration matrices and its timestamp. |
execute (circuits[, had_transpiled]) | A wrapper to interface with quantum backend. |
maybe_refresh_cals_matrix ([timestamp]) | Calculate the time difference from the query of last time. |
set_config (**kwargs) | Set configurations for the quantum instance. |
transpile (circuits) | A wrapper to transpile circuits to allow algorithm access the transpiled circuits. |
Attributes
backend | Return BaseBackend backend object. |
backend_config | Getter of backend_config. |
backend_name | Return backend name. |
backend_options | Getter of backend_options. |
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. |
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 |
assemble
backend
Return BaseBackend backend object.
backend_config
Getter of backend_config.
backend_name
Return backend name.
backend_options
Getter of backend_options.
cals_matrix
cals_matrix(qubit_index=None)
Get the stored calibration matrices and its timestamp.
Parameters
- qubit_index (list[int]) – the qubit index of corresponding calibration matrix.
- None (If) –
- all stored calibration matrices. (return) –
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(np.ndarray, int)
cals_matrix_refresh_period
returns matrix refresh period
circuit_summary
Getter of circuit summary.
compile_config
Getter of compile_config.
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
) – whether or not circuits had been transpiled
Return type
Returns
Result object
TODO: Maybe we can combine the circuits for the main ones and calibration circuits before
assembling to the qobj.
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.
maybe_refresh_cals_matrix
maybe_refresh_cals_matrix(timestamp=None)
Calculate the time difference from the query of last time.
Returns
whether or not refresh the cals_matrix
Return type
bool
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.
set_config
set_config(**kwargs)
Set configurations for the quantum instance.
skip_qobj_validation
checks if skip qobj validation
transpile
transpile(circuits)
A wrapper to transpile circuits to allow algorithm access the transpiled circuits. :type circuits: Union
[QuantumCircuit
, List
[QuantumCircuit
]] :param circuits: circuits to transpile
Return type
List
[QuantumCircuit
]
Returns
The transpiled circuits, it is always a list even though the length is one.