Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the parameter expression case for RZZ validation #2035

Merged
merged 5 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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])])