301 lines
15 KiB
Plaintext
301 lines
15 KiB
Plaintext
---
|
||
title: QuantumInstance
|
||
description: API reference for qiskit.utils.QuantumInstance
|
||
in_page_toc_min_heading_level: 1
|
||
python_api_type: class
|
||
python_api_name: qiskit.utils.QuantumInstance
|
||
---
|
||
|
||
# QuantumInstance
|
||
|
||
<Class id="qiskit.utils.QuantumInstance" isDedicatedPage={true} github="https://github.com/qiskit/qiskit/tree/stable/0.25/qiskit/utils/quantum_instance.py" signature="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)" modifiers="class">
|
||
Bases: [`object`](https://docs.python.org/3/library/functions.html#object "(in Python v3.12)")
|
||
|
||
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.
|
||
|
||
<Admonition title="Deprecated since version 0.24.0" type="danger">
|
||
The class `qiskit.utils.quantum_instance.QuantumInstance` is deprecated as of qiskit-terra 0.24.0. It will be removed no earlier than 3 months after the release date. For code migration guidelines, visit [https://qisk.it/qi\_migration](https://qisk.it/qi_migration).
|
||
</Admonition>
|
||
|
||
**Parameters**
|
||
|
||
* **backend** ([*Backend*](qiskit.providers.Backend "qiskit.providers.Backend")) – Instance of selected backend
|
||
* **shots** ([*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.12)") *| 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*](https://docs.python.org/3/library/functions.html#int "(in Python v3.12)") *| None*) – Random seed for simulators
|
||
* **basis\_gates** ([*List*](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.12)")*\[*[*str*](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.12)")*] | 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()`](#qiskit.utils.QuantumInstance.transpile "qiskit.utils.QuantumInstance.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()`](#qiskit.utils.QuantumInstance.transpile "qiskit.utils.QuantumInstance.transpile") method with the argument `pass_manager=quantum_instance.bound_pass_manager`. manager should also be run.
|
||
* **seed\_transpiler** ([*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.12)") *| None*) – The random seed for circuit mapper
|
||
* **optimization\_level** ([*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.12)") *| 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*](https://docs.python.org/3/library/typing.html#typing.Dict "(in Python v3.12)") *| 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*](https://docs.python.org/3/library/functions.html#float "(in Python v3.12)") *| None*) – Seconds to wait for job. If None, wait indefinitely.
|
||
* **wait** ([*float*](https://docs.python.org/3/library/functions.html#float "(in Python v3.12)")) – Seconds between queries for job result
|
||
* **skip\_qobj\_validation** ([*bool*](https://docs.python.org/3/library/functions.html#bool "(in Python v3.12)")) – Bypass Qobj validation to decrease circuit processing time during submission to backend.
|
||
* **measurement\_error\_mitigation\_cls** ([*Callable*](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.12)") *| None*) – The approach to mitigate measurement errors. The classes [`CompleteMeasFitter`](qiskit.utils.mitigation.CompleteMeasFitter "qiskit.utils.mitigation.CompleteMeasFitter") or [`TensoredMeasFitter`](qiskit.utils.mitigation.TensoredMeasFitter "qiskit.utils.mitigation.TensoredMeasFitter") from the [`qiskit.utils.mitigation`](utils_mitigation#module-qiskit.utils.mitigation "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*](https://docs.python.org/3/library/functions.html#int "(in Python v3.12)")) – How often to refresh the calibration matrix in measurement mitigation. in minutes
|
||
* **measurement\_error\_mitigation\_shots** ([*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.12)") *| None*) – The number of shots number for building calibration matrix. If None, the main shots parameter value is used.
|
||
* **job\_callback** ([*Callable*](https://docs.python.org/3/library/typing.html#typing.Callable "(in Python v3.12)") *| 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*](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.12)")*\[*[*List*](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.12)")*\[*[*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.12)")*]] | 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*](https://docs.python.org/3/library/functions.html#int "(in Python v3.12)")) – positive non-zero number of trials for the job set (-1 for infinite trials) (default: 50)
|
||
|
||
**Raises**
|
||
|
||
* [**QiskitError**](exceptions#qiskit.exceptions.QiskitError "qiskit.exceptions.QiskitError") – the shots exceeds the maximum number of shots
|
||
* [**QiskitError**](exceptions#qiskit.exceptions.QiskitError "qiskit.exceptions.QiskitError") – set noise model but the backend does not support that
|
||
* [**QiskitError**](exceptions#qiskit.exceptions.QiskitError "qiskit.exceptions.QiskitError") – set backend\_options but the backend does not support that
|
||
|
||
## Attributes
|
||
|
||
### backend
|
||
|
||
<Attribute id="qiskit.utils.QuantumInstance.backend">
|
||
Return Backend backend object.
|
||
</Attribute>
|
||
|
||
### backend\_config
|
||
|
||
<Attribute id="qiskit.utils.QuantumInstance.backend_config">
|
||
Getter of backend\_config.
|
||
</Attribute>
|
||
|
||
### backend\_name
|
||
|
||
<Attribute id="qiskit.utils.QuantumInstance.backend_name">
|
||
Return backend name.
|
||
</Attribute>
|
||
|
||
### backend\_options
|
||
|
||
<Attribute id="qiskit.utils.QuantumInstance.backend_options">
|
||
Getter of backend\_options.
|
||
</Attribute>
|
||
|
||
### bound\_pass\_manager
|
||
|
||
<Attribute id="qiskit.utils.QuantumInstance.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’]
|
||
</Attribute>
|
||
|
||
### cals\_matrix\_refresh\_period
|
||
|
||
<Attribute id="qiskit.utils.QuantumInstance.cals_matrix_refresh_period">
|
||
returns matrix refresh period
|
||
</Attribute>
|
||
|
||
### circuit\_summary
|
||
|
||
<Attribute id="qiskit.utils.QuantumInstance.circuit_summary">
|
||
Getter of circuit summary.
|
||
</Attribute>
|
||
|
||
### compile\_config
|
||
|
||
<Attribute id="qiskit.utils.QuantumInstance.compile_config">
|
||
Getter of compile\_config.
|
||
</Attribute>
|
||
|
||
### is\_local
|
||
|
||
<Attribute id="qiskit.utils.QuantumInstance.is_local">
|
||
Return True if backend is a local backend.
|
||
</Attribute>
|
||
|
||
### is\_simulator
|
||
|
||
<Attribute id="qiskit.utils.QuantumInstance.is_simulator">
|
||
Return True if backend is a simulator.
|
||
</Attribute>
|
||
|
||
### is\_statevector
|
||
|
||
<Attribute id="qiskit.utils.QuantumInstance.is_statevector">
|
||
Return True if backend is a statevector-type simulator.
|
||
</Attribute>
|
||
|
||
### max\_job\_retries
|
||
|
||
<Attribute id="qiskit.utils.QuantumInstance.max_job_retries">
|
||
Getter of max tries
|
||
</Attribute>
|
||
|
||
### measurement\_error\_mitigation\_cls
|
||
|
||
<Attribute id="qiskit.utils.QuantumInstance.measurement_error_mitigation_cls">
|
||
returns measurement error mitigation cls
|
||
</Attribute>
|
||
|
||
### measurement\_error\_mitigation\_shots
|
||
|
||
<Attribute id="qiskit.utils.QuantumInstance.measurement_error_mitigation_shots">
|
||
returns measurement error mitigation shots
|
||
</Attribute>
|
||
|
||
### noise\_config
|
||
|
||
<Attribute id="qiskit.utils.QuantumInstance.noise_config">
|
||
Getter of noise\_config.
|
||
</Attribute>
|
||
|
||
### qjob\_config
|
||
|
||
<Attribute id="qiskit.utils.QuantumInstance.qjob_config">
|
||
Getter of qjob\_config.
|
||
</Attribute>
|
||
|
||
### run\_config
|
||
|
||
<Attribute id="qiskit.utils.QuantumInstance.run_config">
|
||
Getter of run\_config.
|
||
</Attribute>
|
||
|
||
### skip\_qobj\_validation
|
||
|
||
<Attribute id="qiskit.utils.QuantumInstance.skip_qobj_validation">
|
||
checks if skip qobj validation
|
||
</Attribute>
|
||
|
||
### time\_taken
|
||
|
||
<Attribute id="qiskit.utils.QuantumInstance.time_taken">
|
||
Accumulated time taken for execution.
|
||
</Attribute>
|
||
|
||
### unbound\_pass\_manager
|
||
|
||
<Attribute id="qiskit.utils.QuantumInstance.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’]
|
||
</Attribute>
|
||
|
||
## Methods
|
||
|
||
### assemble
|
||
|
||
<Function id="qiskit.utils.QuantumInstance.assemble" signature="assemble(circuits)">
|
||
assemble circuits
|
||
|
||
**Return type**
|
||
|
||
[*Qobj*](qiskit.qobj.Qobj "qiskit.qobj.Qobj")
|
||
</Function>
|
||
|
||
### cals\_matrix
|
||
|
||
<Function id="qiskit.utils.QuantumInstance.cals_matrix" signature="cals_matrix(qubit_index=None)">
|
||
Get the stored calibration matrices and its timestamp.
|
||
|
||
**Parameters**
|
||
|
||
**qubit\_index** ([*List*](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.12)")*\[*[*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.12)")*] | 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*](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.12)")\[[*ndarray*](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v1.26)"), [float](https://docs.python.org/3/library/functions.html#float "(in Python v3.12)")] | [*Dict*](https://docs.python.org/3/library/typing.html#typing.Dict "(in Python v3.12)")\[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.12)"), [*Tuple*](https://docs.python.org/3/library/typing.html#typing.Tuple "(in Python v3.12)")\[[*ndarray*](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v1.26)"), [float](https://docs.python.org/3/library/functions.html#float "(in Python v3.12)")]] | None
|
||
</Function>
|
||
|
||
### execute
|
||
|
||
<Function id="qiskit.utils.QuantumInstance.execute" signature="execute(circuits, had_transpiled=False)">
|
||
A wrapper to interface with quantum backend.
|
||
|
||
**Parameters**
|
||
|
||
* **circuits** (*Union\['QuantumCircuit', List\['QuantumCircuit']]*) – circuits to execute
|
||
* **had\_transpiled** ([*bool*](https://docs.python.org/3/library/functions.html#bool "(in Python v3.12)")) – whether or not circuits had been transpiled
|
||
|
||
**Raises**
|
||
|
||
* [**QiskitError**](exceptions#qiskit.exceptions.QiskitError "qiskit.exceptions.QiskitError") – Invalid error mitigation fitter class
|
||
* [**QiskitError**](exceptions#qiskit.exceptions.QiskitError "qiskit.exceptions.QiskitError") – TensoredMeasFitter class doesn’t support subset fitter
|
||
* [**MissingOptionalLibraryError**](exceptions#qiskit.exceptions.MissingOptionalLibraryError "qiskit.exceptions.MissingOptionalLibraryError") – Ignis not installed
|
||
|
||
**Returns**
|
||
|
||
result object
|
||
|
||
**Return type**
|
||
|
||
[Result](qiskit.result.Result "qiskit.result.Result")
|
||
|
||
**TODO: Maybe we can combine the circuits for the main ones and calibration circuits before**
|
||
|
||
assembling to the qobj.
|
||
</Function>
|
||
|
||
### maybe\_refresh\_cals\_matrix
|
||
|
||
<Function id="qiskit.utils.QuantumInstance.maybe_refresh_cals_matrix" signature="maybe_refresh_cals_matrix(timestamp=None)">
|
||
Calculate the time difference from the query of last time.
|
||
|
||
**Parameters**
|
||
|
||
**timestamp** ([*float*](https://docs.python.org/3/library/functions.html#float "(in Python v3.12)") *| None*) – timestamp
|
||
|
||
**Returns**
|
||
|
||
Whether or not refresh the cals\_matrix
|
||
|
||
**Return type**
|
||
|
||
[bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.12)")
|
||
</Function>
|
||
|
||
### reset\_execution\_results
|
||
|
||
<Function id="qiskit.utils.QuantumInstance.reset_execution_results" signature="reset_execution_results()">
|
||
Reset execution results
|
||
</Function>
|
||
|
||
### set\_config
|
||
|
||
<Function id="qiskit.utils.QuantumInstance.set_config" signature="set_config(**kwargs)">
|
||
Set configurations for the quantum instance.
|
||
</Function>
|
||
|
||
### transpile
|
||
|
||
<Function id="qiskit.utils.QuantumInstance.transpile" signature="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’]
|
||
</Function>
|
||
</Class>
|
||
|