Skip to content

Commit

Permalink
check parameter_binds arguments for parameterized circuits (Qiskit#1817)
Browse files Browse the repository at this point in the history
Aer raises an error if `parameter_binds` is not specified though circuits have parameters.
This resolves the following issue:
Qiskit#1773
  • Loading branch information
hhorii authored May 31, 2023
1 parent 8331cda commit 3954278
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions qiskit_aer/backends/aerbackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ def _run_circuits(self, circuits, parameter_binds, **run_options):
circuits, noise_model = self._compile(circuits, **run_options)
if parameter_binds:
run_options["parameterizations"] = self._convert_binds(circuits, parameter_binds)
elif not all([len(circuit.parameters) == 0 for circuit in circuits]):
raise AerError("circuits have parameters but parameter_binds is not specified.")
config = generate_aer_config(circuits, self.options, **run_options)

# Submit job
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
fixes:
- |
Since 0.12.0, parameter values in circuits are temporarily replaced with constant values
and parameter values are assigned in C++ library. Therefore, if `parameter_binds` is specified,
simulator returns results with the constnat values as paramter values. With this commit,
Aer raises an error if `parameter_binds` is not specified though circuits have parameters.
13 changes: 13 additions & 0 deletions test/terra/backends/test_parameterized_qobj.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,19 @@ def test_parameters_with_barrier(self):
self.assertSuccess(res)
self.assertEqual(res.get_counts(), {"111": 1024})

def test_check_parameter_binds_exist(self):
"""Test parameter_binds exists to simulate parameterized circuits"""

shots = 1000
backend = AerSimulator()
circuit = QuantumCircuit(2)
theta = Parameter("theta")
circuit.rx(theta, 0)
circuit.cx(0, 1)
circuit.measure_all()
with self.assertRaises(AerError):
res = backend.run(circuit, shots=shots).result()

def test_global_phase_parameters(self):
"""Test parameterized global phase"""
backend = AerSimulator()
Expand Down

0 comments on commit 3954278

Please sign in to comment.