diff --git a/qiskit_aer/backends/aerbackend.py b/qiskit_aer/backends/aerbackend.py index 8aa5cc58da..d850aa19a6 100644 --- a/qiskit_aer/backends/aerbackend.py +++ b/qiskit_aer/backends/aerbackend.py @@ -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 diff --git a/releasenotes/notes/check_parameter_binds_exist-9d52c665d5f94dde.yaml b/releasenotes/notes/check_parameter_binds_exist-9d52c665d5f94dde.yaml new file mode 100644 index 0000000000..2b61f5281f --- /dev/null +++ b/releasenotes/notes/check_parameter_binds_exist-9d52c665d5f94dde.yaml @@ -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. diff --git a/test/terra/backends/test_parameterized_qobj.py b/test/terra/backends/test_parameterized_qobj.py index bbfe913d1a..f5b26bfc22 100644 --- a/test/terra/backends/test_parameterized_qobj.py +++ b/test/terra/backends/test_parameterized_qobj.py @@ -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()