EstimatorV1
class EstimatorV1(backend=None, session=None, options=None)
Class for interacting with Qiskit Runtime Estimator primitive service.
The EstimatorV1
primitives have been deprecated in 0.23, released on April 15, 2024. See the V2 migration guide. for more details. The EstimatorV1
support will be removed no earlier than July 15, 2024.
Qiskit Runtime Estimator primitive service estimates expectation values of quantum circuits and observables.
The run()
can be used to submit circuits, observables, and parameters to the Estimator primitive.
You are encouraged to use Session
to open a session, during which you can invoke one or more primitives. Jobs submitted within a session are prioritized by the scheduler.
Example:
from qiskit.circuit.library import RealAmplitudes
from qiskit.quantum_info import SparsePauliOp
from qiskit_ibm_runtime import QiskitRuntimeService, Estimator
service = QiskitRuntimeService(channel="ibm_cloud")
psi1 = RealAmplitudes(num_qubits=2, reps=2)
H1 = SparsePauliOp.from_list([("II", 1), ("IZ", 2), ("XI", 3)])
H2 = SparsePauliOp.from_list([("IZ", 1)])
H3 = SparsePauliOp.from_list([("ZI", 1), ("ZZ", 1)])
with Session(service=service, backend="ibmq_qasm_simulator") as session:
estimator = Estimator(session=session)
theta1 = [0, 1, 1, 2, 3, 5]
# calculate [ <psi1(theta1)|H1|psi1(theta1)> ]
psi1_H1 = estimator.run(circuits=[psi1], observables=[H1], parameter_values=[theta1])
print(psi1_H1.result())
# calculate [ <psi1(theta1)|H2|psi1(theta1)>, <psi1(theta1)|H3|psi1(theta1)> ]
psi1_H23 = estimator.run(
circuits=[psi1, psi1],
observables=[H2, H3],
parameter_values=[theta1]*2
)
print(psi1_H23.result())
Initializes the Estimator primitive.
Parameters
-
backend (
Union
[str
,IBMBackend
,None
]) – Backend to run the primitive. This can be a backend name or anIBMBackend
instance. If a name is specified, the default account (e.g.QiskitRuntimeService()
) is used. -
session (
Optional
[Session
]) –Session in which to call the primitive.
If both
session
andbackend
are specified,session
takes precedence. If neither is specified, and the primitive is created inside aqiskit_ibm_runtime.Session
context manager, then the session is used. Otherwise if IBM Cloud channel is used, a default backend is selected. -
options (
Union
[Dict
,Options
,None
]) – Primitive options, seeOptions
for detailed description. Thebackend
keyword is still supported but is deprecated.
Attributes
options
Return options values for the sampler. :rtype: Options
:returns: options
session
Return session used by this primitive.
Return type
Optional
[Session
]
Returns
Session used by this primitive, or None
if session is not used.
version
Default value: 1
Methods
run
run(circuits, observables, parameter_values=None, **kwargs)
Submit a request to the estimator primitive.
Parameters
- circuits (QuantumCircuit | Sequence[QuantumCircuit]) – a (parameterized)
QuantumCircuit
or a list of (parameterized)QuantumCircuit
. - observables (Sequence[BaseOperator | str] | BaseOperator | str) – Observable objects.
- parameter_values (Sequence[float] | Sequence[Sequence[float]] | None) – Concrete parameters to be bound.
- **kwargs – Individual options to overwrite the default primitive options.
Return type
Returns
Submitted job. The result of the job is an instance of qiskit.primitives.EstimatorResult
.
Raises
ValueError – Invalid arguments are given.
set_options
set_options(**fields)
Set options values for the sampler.
Parameters
**fields – The fields to update the options
Return type
None