Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion qiskit/algorithms/gradients/base_estimator_gradient.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,6 @@ def _get_local_run_options(self, run_options: dict) -> Options:
Returns:
The updated run options.
"""
run_opts = copy(self._estimator.run_options)
run_opts = copy(self._estimator.options)
run_opts.update_options(**run_options)
return run_opts
2 changes: 1 addition & 1 deletion qiskit/algorithms/gradients/base_sampler_gradient.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,6 @@ def _get_local_run_options(self, run_options: dict) -> dict:
Returns:
The updated run options.
"""
run_opts = copy(self._sampler.run_options)
run_opts = copy(self._sampler.options)
run_opts.update_options(**run_options)
return run_opts
18 changes: 9 additions & 9 deletions qiskit/primitives/base_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def __init__(
circuits: Iterable[QuantumCircuit] | QuantumCircuit | None = None,
observables: Iterable[SparsePauliOp] | SparsePauliOp | None = None,
parameters: Iterable[Iterable[Parameter]] | None = None,
run_options: dict | None = None,
options: dict | None = None,
):
"""
Creating an instance of an Estimator, or using one in a ``with`` context opens a session that
Expand All @@ -147,7 +147,7 @@ def __init__(
will be bound. Defaults to ``[circ.parameters for circ in circuits]``
The indexing is such that ``parameters[i, j]`` is the j-th formal parameter of
``circuits[i]``.
run_options: runtime options.
options: Default options.

Raises:
QiskitError: For mismatch of circuits and parameters list.
Expand Down Expand Up @@ -189,8 +189,8 @@ def __init__(
f"expected {circ.num_parameters}, actual {len(params)}."
)
self._run_options = Options()
if run_options is not None:
self._run_options.update_options(**run_options)
if options is not None:
self._run_options.update_options(**options)

def __new__(
cls,
Expand Down Expand Up @@ -265,15 +265,15 @@ def parameters(self) -> tuple[ParameterView, ...]:
return tuple(self._parameters)

@property
def run_options(self) -> Options:
def options(self) -> Options:
"""Return options values for the estimator.

Returns:
run_options
options
"""
return self._run_options

def set_run_options(self, **fields) -> BaseEstimator:
def set_options(self, **fields) -> BaseEstimator:
"""Set options values for the estimator.

Args:
Expand Down Expand Up @@ -409,7 +409,7 @@ def __call__(
f"The number of circuits is {len(self.observables)}, "
f"but the index {max(observables)} is given."
)
run_opts = copy(self.run_options)
run_opts = copy(self.options)
run_opts.update_options(**run_options)

return self._call(
Expand Down Expand Up @@ -520,7 +520,7 @@ def run(
f"not match the number of qubits of the {i}-th observable "
f"({observable.num_qubits})."
)
run_opts = copy(self.run_options)
run_opts = copy(self.options)
run_opts.update_options(**run_options)

return self._run(
Expand Down
18 changes: 9 additions & 9 deletions qiskit/primitives/base_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ def __init__(
self,
circuits: Iterable[QuantumCircuit] | QuantumCircuit | None = None,
parameters: Iterable[Iterable[Parameter]] | None = None,
run_options: dict | None = None,
options: dict | None = None,
):
"""
Args:
circuits: Quantum circuits to be executed.
parameters: Parameters of each of the quantum circuits.
Defaults to ``[circ.parameters for circ in circuits]``.
run_options: Default runtime options.
options: Default options.

Raises:
QiskitError: For mismatch of circuits and parameters list.
Expand Down Expand Up @@ -158,8 +158,8 @@ def __init__(
f"and circuits ({len(self._circuits)})"
)
self._run_options = Options()
if run_options is not None:
self._run_options.update_options(**run_options)
if options is not None:
self._run_options.update_options(**options)

def __new__(
cls,
Expand Down Expand Up @@ -217,15 +217,15 @@ def parameters(self) -> tuple[ParameterView, ...]:
return tuple(self._parameters)

@property
def run_options(self) -> Options:
def options(self) -> Options:
"""Return options values for the estimator.

Returns:
run_options
options
"""
return self._run_options

def set_run_options(self, **fields) -> BaseSampler:
def set_options(self, **fields):
"""Set options values for the estimator.

Args:
Expand Down Expand Up @@ -309,7 +309,7 @@ def __call__(
f"The number of circuits is {len(self.circuits)}, "
f"but the index {max(circuits)} is given."
)
run_opts = copy(self.run_options)
run_opts = copy(self.options)
run_opts.update_options(**run_options)

return self._call(
Expand Down Expand Up @@ -401,7 +401,7 @@ def run(
f" the used classical bits ({set(mapping.values())})."
)

run_opts = copy(self.run_options)
run_opts = copy(self.options)
run_opts.update_options(**run_options)

return self._run(
Expand Down
6 changes: 3 additions & 3 deletions qiskit/primitives/estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ def __init__(
circuits: QuantumCircuit | Iterable[QuantumCircuit] | None = None,
observables: BaseOperator | PauliSumOp | Iterable[BaseOperator | PauliSumOp] | None = None,
parameters: Iterable[Iterable[Parameter]] | None = None,
run_options: dict | None = None,
options: dict | None = None,
):
"""
Args:
circuits: circuits that represent quantum states.
observables: observables to be estimated.
parameters: Parameters of each of the quantum circuits.
Defaults to ``[circ.parameters for circ in circuits]``.
run_options: Default runtime options.
options: Default options.

Raises:
QiskitError: if some classical bits are not used for measurements.
Expand All @@ -81,7 +81,7 @@ def __init__(
circuits=circuits,
observables=observables, # type: ignore
parameters=parameters,
run_options=run_options,
options=options,
)
self._is_closed = False

Expand Down
6 changes: 3 additions & 3 deletions qiskit/primitives/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ def __init__(
self,
circuits: QuantumCircuit | Iterable[QuantumCircuit] | None = None,
parameters: Iterable[Iterable[Parameter]] | None = None,
run_options: dict | None = None,
options: dict | None = None,
):
"""
Args:
circuits: circuits to be executed
parameters: Parameters of each of the quantum circuits.
Defaults to ``[circ.parameters for circ in circuits]``.
run_options: Default runtime options.
options: Default options.

Raises:
QiskitError: if some classical bits are not used for measurements.
Expand All @@ -76,7 +76,7 @@ def __init__(
preprocessed_circuits.append(circuit)
else:
preprocessed_circuits = None
super().__init__(preprocessed_circuits, parameters, run_options)
super().__init__(preprocessed_circuits, parameters, options)
self._is_closed = False

def _call(
Expand Down
6 changes: 3 additions & 3 deletions test/python/algorithms/test_estimator_gradient.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from qiskit.circuit.library import EfficientSU2, RealAmplitudes
from qiskit.circuit.library.standard_gates import RXXGate, RYYGate, RZXGate, RZZGate
from qiskit.primitives import Estimator
from qiskit.quantum_info import SparsePauliOp, Operator
from qiskit.quantum_info import Operator, SparsePauliOp
from qiskit.quantum_info.random import random_pauli_list
from qiskit.test import QiskitTestCase

Expand Down Expand Up @@ -382,13 +382,13 @@ def test_gradient_random_parameters(self, grad):
SPSAEstimatorGradient,
],
)
def test_run_options(self, grad):
def test_options(self, grad):
"""Test estimator gradient's run options"""
a = Parameter("a")
qc = QuantumCircuit(1)
qc.rx(a, 0)
op = SparsePauliOp.from_list([("Z", 1)])
estimator = Estimator(run_options={"shots": 100})
estimator = Estimator(options={"shots": 100})
with self.subTest("estimator"):
if grad is FiniteDiffEstimatorGradient or grad is SPSAEstimatorGradient:
gradient = grad(estimator, epsilon=1e-6)
Expand Down
2 changes: 1 addition & 1 deletion test/python/algorithms/test_sampler_gradient.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ def test_run_options(self, grad):
qc = QuantumCircuit(1)
qc.rx(a, 0)
qc.measure_all()
sampler = Sampler(run_options={"shots": 100})
sampler = Sampler(options={"shots": 100})
with self.subTest("sampler"):
if grad is FiniteDiffSamplerGradient or grad is SPSASamplerGradient:
gradient = grad(sampler, epsilon=1e-6)
Expand Down
16 changes: 8 additions & 8 deletions test/python/primitives/test_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,15 +568,15 @@ def test_run_with_shots_option(self):
self.assertIsInstance(result, EstimatorResult)
np.testing.assert_allclose(result.values, [-1.307397243478641])

def test_run_options(self):
"""Test for run_options"""
def test_options(self):
"""Test for options"""
with self.subTest("init"):
estimator = Estimator(run_options={"shots": 3000})
self.assertEqual(estimator.run_options.get("shots"), 3000)
with self.subTest("set_run_options"):
estimator.set_run_options(shots=1024, seed=15)
self.assertEqual(estimator.run_options.get("shots"), 1024)
self.assertEqual(estimator.run_options.get("seed"), 15)
estimator = Estimator(options={"shots": 3000})
self.assertEqual(estimator.options.get("shots"), 3000)
with self.subTest("set_options"):
estimator.set_options(shots=1024, seed=15)
self.assertEqual(estimator.options.get("shots"), 1024)
self.assertEqual(estimator.options.get("seed"), 15)
with self.subTest("run"):
result = estimator.run(
[self.ansatz],
Expand Down
16 changes: 8 additions & 8 deletions test/python/primitives/test_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,15 +672,15 @@ def test_primitive_job_status_done(self):
job = sampler.run(circuits=[bell])
self.assertEqual(job.status(), JobStatus.DONE)

def test_run_options(self):
"""Test for run_options"""
def test_options(self):
"""Test for options"""
with self.subTest("init"):
sampler = Sampler(run_options={"shots": 3000})
self.assertEqual(sampler.run_options.get("shots"), 3000)
with self.subTest("set_run_options"):
sampler.set_run_options(shots=1024, seed=15)
self.assertEqual(sampler.run_options.get("shots"), 1024)
self.assertEqual(sampler.run_options.get("seed"), 15)
sampler = Sampler(options={"shots": 3000})
self.assertEqual(sampler.options.get("shots"), 3000)
with self.subTest("set_options"):
sampler.set_options(shots=1024, seed=15)
self.assertEqual(sampler.options.get("shots"), 1024)
self.assertEqual(sampler.options.get("seed"), 15)
with self.subTest("run"):
params, target = self._generate_params_target([1])
result = sampler.run([self._pqc], parameter_values=params).result()
Expand Down