Skip to content

Commit

Permalink
Add workaround for parameter failure with data being in Rust now
Browse files Browse the repository at this point in the history
  • Loading branch information
woodsp-ibm committed Jul 16, 2024
1 parent b257361 commit a50b9ec
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions qiskit_algorithms/gradients/reverse/derive_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ def derive_circuit(
c = complex(1)
for i, term in enumerate(product_rule_term):
c *= term[0]
# Qiskit changed the format of the stored value. The newer Qiskit has this internal
# method to go from the older (legacy) format to new. This logic may need updating
# at some point if this internal method goes away.
if hasattr(summand_circuit.data, "_resolve_legacy_value"):
value = summand_circuit.data._resolve_legacy_value(term[1], *op_context[i])
summand_circuit.data.append(value)
Expand Down
9 changes: 8 additions & 1 deletion qiskit_algorithms/gradients/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of a Qiskit project.
#
# (C) Copyright IBM 2022, 2023.
# (C) Copyright IBM 2022, 2024.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand Down Expand Up @@ -137,6 +137,13 @@ def _make_lin_comb_gradient_circuit(
lin_comb_circuit.h(qr_aux)
if add_measurement:
lin_comb_circuit.measure(qr_aux, cr_aux)
# This next line which assigns data is a workaround otherwise the
# circuit parameters may not be properly recognized as data is now
# managed in Rust and changing things may break parameters - making a
# copy of itself by assignment sorts things out.
# See https://github.com/Qiskit/qiskit/blob/main/releasenotes/notes
# /circuit-gates-rust-5c6ab6c58f7fd2c9.yaml#L47-L79
lin_comb_circuit.data = lin_comb_circuit.data
lin_comb_circuits[p] = lin_comb_circuit

return lin_comb_circuits
Expand Down

0 comments on commit a50b9ec

Please sign in to comment.