diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b84f7160..2a5442675 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,15 +4,15 @@ ### Improvements ๐Ÿ›  -* The UI for passing parameters to a ``qfunc`` generated when loading a Qiskit ``QuantumCircuit`` - into PennyLane is updated to allow passing parameters as args or kwargs, rather than as +* The UI for passing parameters to a ``qfunc`` generated when loading a Qiskit ``QuantumCircuit`` + into PennyLane is updated to allow passing parameters as args or kwargs, rather than as a dictionary. The old dictionary UI continues to be supported. [(#406)](https://github.com/PennyLaneAI/pennylane-qiskit/pull/406) [(#428)](https://github.com/PennyLaneAI/pennylane-qiskit/pull/428) * Measurement operations are now added to the PennyLane template when a ``QuantumCircuit`` is converted using `load`. Additionally, one can override any existing terminal - measurements by providing a list of PennyLane + measurements by providing a list of PennyLane `measurements `_ themselves. [(#405)](https://github.com/PennyLaneAI/pennylane-qiskit/pull/405) @@ -29,6 +29,9 @@ ``Barrier``, ``CYGate``, ``CHGate``, ``CPhase``, ``CCZGate``, ``ECRGate``, and ``GlobalPhaseGate``. [(#449)](https://github.com/PennyLaneAI/pennylane-qiskit/pull/449) +* Unused parameters are now ignored when a `QuantumCircuit` is converted using `load`. + [(#454)](https://github.com/PennyLaneAI/pennylane-qiskit/pull/454) + ### Breaking changes ๐Ÿ’” ### Deprecations ๐Ÿ‘‹ @@ -41,6 +44,7 @@ This release contains contributions from (in alphabetical order): +Mikhail Andrenkov Utkarsh Azad Lillian Frederiksen @@ -49,18 +53,18 @@ Lillian Frederiksen ### Bug fixes ๐Ÿ› -* The kwargs `job_tags` and `session_id` are passed to the correct arguments in the - `circuit_runner` device so that they will be used in the Qiskit backend; these +* The kwargs `job_tags` and `session_id` are passed to the correct arguments in the + `circuit_runner` device so that they will be used in the Qiskit backend; these were previously ignored. [(#358)](https://github.com/PennyLaneAI/pennylane-qiskit/pull/358) -* The `generate_samples` method for the `IBMQSamplerDevice` is updated to get counts - from the nearest probability distribution rather than the quasi-distribution (which - may contain negative probabilities and therefore raise errors). +* The `generate_samples` method for the `IBMQSamplerDevice` is updated to get counts + from the nearest probability distribution rather than the quasi-distribution (which + may contain negative probabilities and therefore raise errors). [(#357)](https://github.com/PennyLaneAI/pennylane-qiskit/pull/357) - -* The `generate_samples` method for the `IBMQSamplerDevice` now avoids raising an - indexing error when some states are not populated, and labels states according to + +* The `generate_samples` method for the `IBMQSamplerDevice` now avoids raising an + indexing error when some states are not populated, and labels states according to the Pennylane convention instead of Qiskit convention. [(#357)](https://github.com/PennyLaneAI/pennylane-qiskit/pull/357) @@ -83,7 +87,7 @@ Francesco Scala ### Bug fixes ๐Ÿ› -* Update conversion of PennyLane to Qiskit operators to accommodate +* Update conversion of PennyLane to Qiskit operators to accommodate the addition of Singleton classes in the newest version of Qiskit. [(#347)](https://github.com/PennyLaneAI/pennylane-qiskit/pull/347) @@ -315,10 +319,10 @@ Mikhail Andrenkov, Christina Lee, Romain Moyard, Antal Szรกva * Fix runtime sampler due to changes on Qiskit side. [(#201)](https://github.com/PennyLaneAI/pennylane-qiskit/pull/201) - + * Pin `jinja2` to 3.0.3 because of sphinx incompatibility. [(#207)](https://github.com/PennyLaneAI/pennylane-qiskit/pull/207) - + ### Contributors This release contains contributions from (in alphabetical order): @@ -326,7 +330,7 @@ This release contains contributions from (in alphabetical order): Samuel Banning, Romain Moyard --- - + # Release 0.22.0 ### Improvements @@ -334,7 +338,7 @@ Samuel Banning, Romain Moyard * Changed a validation check such that it handles qubit numbers represented as strings. [(#184)](https://github.com/PennyLaneAI/pennylane-qiskit/pull/184) - + * Changed the VQE callback function for SciPy optimizers. [(#187)](https://github.com/PennyLaneAI/pennylane-qiskit/pull/187) @@ -346,7 +350,7 @@ Samuel Banning, Romain Moyard * Changed the access to Hamiltonian terms `hamiltonian.terms()` as a method. [(#190)](https://github.com/PennyLaneAI/pennylane-qiskit/pull/190) - + ### Contributors This release contains contributions from (in alphabetical order): diff --git a/pennylane_qiskit/converter.py b/pennylane_qiskit/converter.py index 79d447ce9..a04976800 100644 --- a/pennylane_qiskit/converter.py +++ b/pennylane_qiskit/converter.py @@ -250,7 +250,8 @@ def _check_circuit_and_assign_parameters( # we must remove them from the binding dictionary before binding. del params[k] - return quantum_circuit.assign_parameters(params) + # Disabling "strict" assignment allows extra parameters to be ignored. + return quantum_circuit.assign_parameters(params, strict=False) def _get_operation_params(instruction, unbound_params) -> list: diff --git a/requirements.txt b/requirements.txt index b36af16c2..ac3dfc285 100644 --- a/requirements.txt +++ b/requirements.txt @@ -29,7 +29,7 @@ qiskit-aer==0.13.3 qiskit-ibm-runtime==0.20.0 qiskit-ibm-provider==0.10.0 qiskit-ignis==0.7.1 -qiskit-terra==0.46.0 +qiskit-terra==0.45.3 requests==2.31.0 requests-ntlm==1.2.0 retworkx==0.14.0 diff --git a/tests/test_converter.py b/tests/test_converter.py index 3917582dc..5fc8ca3ef 100644 --- a/tests/test_converter.py +++ b/tests/test_converter.py @@ -254,38 +254,41 @@ def test_parameter_was_not_bound(self, recorder): ): _check_parameter_bound(theta, unbound_params) - def test_extra_parameters_were_passed(self, recorder): - """Tests that loading raises an error when extra parameters were - passed.""" - - theta = Parameter("ฮธ") - phi = Parameter("ฯ†") - x = np.tensor(0.5, requires_grad=False) - y = np.tensor(0.3, requires_grad=False) + def test_unused_parameters_are_ignored(self, recorder): + """Tests that unused parameters are ignored during assignment.""" + a, b, c = [Parameter(var) for var in "abc"] + v = ParameterVector("v", 2) - qc = QuantumCircuit(3, 1) + qc = QuantumCircuit(1) + qc.rz(a, [0]) quantum_circuit = load(qc) - with pytest.raises(QiskitError): - with recorder: - quantum_circuit(params={theta: x, phi: y}) + with recorder: + quantum_circuit(params={a: 0.1, b: 0.2, c: 0.3, v: [0.4, 0.5]}) - def test_quantum_circuit_error_passing_parameters_not_required(self, recorder): - """Tests the load method raises a QiskitError if arguments - that are not required were passed.""" + assert len(recorder.queue) == 1 + assert recorder.queue[0].name == "RZ" + assert recorder.queue[0].parameters == [0.1] + assert recorder.queue[0].wires == Wires([0]) - theta = Parameter("ฮธ") - angle = np.tensor(0.5, requires_grad=False) + def test_unused_parameter_vector_items_are_ignored(self, recorder): + """Tests that unused parameter vector items are ignored during assignment.""" + a, b = [Parameter(var) for var in "ab"] + v = ParameterVector("v", 3) - qc = QuantumCircuit(3, 1) - qc.z([0]) + qc = QuantumCircuit(1) + qc.rz(v[1], [0]) quantum_circuit = load(qc) - with pytest.raises(QiskitError): - with recorder: - quantum_circuit(params={theta: angle}) + with recorder: + quantum_circuit(params={a: 0.1, b: 0.2, v: [0.3, 0.4, 0.5]}) + + assert len(recorder.queue) == 1 + assert recorder.queue[0].name == "RZ" + assert recorder.queue[0].parameters == [0.4] + assert recorder.queue[0].wires == Wires([0]) def test_quantum_circuit_error_not_qiskit_circuit_passed(self, recorder): """Tests the load method raises a ValueError, if something