Skip to content

Commit

Permalink
Fix the parameter expression case for RZZ validation (#2035)
Browse files Browse the repository at this point in the history
* fix parameter expression case for RZZ

* Update qiskit_ibm_runtime/utils/utils.py

Co-authored-by: Yael Ben-Haim <[email protected]>

* black

* simplify test

* lint

---------

Co-authored-by: Yael Ben-Haim <[email protected]>
  • Loading branch information
t-imamichi and yaelbh authored Nov 11, 2024
1 parent 59a4e02 commit aa393c9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
15 changes: 7 additions & 8 deletions qiskit_ibm_runtime/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
IAMAuthenticator,
)
from ibm_platform_services import ResourceControllerV2 # pylint: disable=import-error
from qiskit.circuit import QuantumCircuit, ControlFlowOp, Parameter
from qiskit.circuit import QuantumCircuit, ControlFlowOp, ParameterExpression
from qiskit.transpiler import Target
from qiskit.providers.backend import BackendV1, BackendV2
from .deprecation import deprecate_function
Expand Down Expand Up @@ -74,14 +74,13 @@ def _is_isa_circuit_helper(circuit: QuantumCircuit, target: Target, qubit_map: D
# accurate).
if (
name == "rzz"
and not isinstance(instruction.operation.params[0], Parameter)
and (
instruction.operation.params[0] < 0.0
or instruction.operation.params[0] > 1.001 * np.pi / 2
)
and not isinstance((param := instruction.operation.params[0]), ParameterExpression)
and (param < 0.0 or param > 1.001 * np.pi / 2)
):
return f"The instruction {name} on qubits {qargs} is supported only for angles in the \
range [0, pi/2], but an angle of {instruction.operation.params[0]} has been provided."
return (
f"The instruction {name} on qubits {qargs} is supported only for angles in the "
f"range [0, pi/2], but an angle of {param} has been provided."
)

if isinstance(operation, ControlFlowOp):
for sub_circ in operation.blocks:
Expand Down
16 changes: 11 additions & 5 deletions test/unit/test_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,14 @@ def test_rzz_validates_only_for_fixed_angles(self):
backend = FakeFractionalBackend()
param = Parameter("p")

circ = QuantumCircuit(2)
circ.rzz(param, 0, 1)

# Should run without an error
SamplerV2(backend).run(pubs=[(circ, [1])])
with self.subTest("parameter"):
circ = QuantumCircuit(2)
circ.rzz(param, 0, 1)
# Should run without an error
SamplerV2(backend).run(pubs=[(circ, [1])])

with self.subTest("parameter expression"):
circ = QuantumCircuit(2)
circ.rzz(2 * param, 0, 1)
# Should run without an error
SamplerV2(backend).run(pubs=[(circ, [0.5])])

0 comments on commit aa393c9

Please sign in to comment.