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

Conversation

t-imamichi
Copy link
Member

@t-imamichi t-imamichi commented Nov 11, 2024

Summary

The current RZZ validation fails with parameter expression as follows.

from qiskit import QuantumCircuit
from qiskit.circuit import Parameter
from qiskit_ibm_runtime import QiskitRuntimeService, SamplerV2

x = Parameter("x")
qc = QuantumCircuit(2, 2)
qc.rzz(2 * x, 0, 1)
qc.measure([0, 1], [0, 1])

service = QiskitRuntimeService(instance="...")
backend = service.backend("ibm_torino", use_fractional_gates=True)

sampler = SamplerV2(backend)
_ = sampler.run([(qc, 0.1)])

0.33.1

Traceback (most recent call last):
  File "/Users/ima/tasks/4_2024/qiskit/runtime/tmp/frac.py", line 14, in <module>
    _ = sampler.run([(qc, 0.1)])
        ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ima/envs/qiskit/lib/python3.12/site-packages/qiskit_ibm_runtime/sampler.py", line 120, in run
    return self._run(coerced_pubs)  # type: ignore[arg-type]
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ima/envs/qiskit/lib/python3.12/site-packages/qiskit_ibm_runtime/base_primitive.py", line 176, in _run
    validate_isa_circuits([pub.circuit], self._backend.target)
  File "/Users/ima/envs/qiskit/lib/python3.12/site-packages/qiskit_ibm_runtime/utils/validations.py", line 88, in validate_isa_circuits
    message = is_isa_circuit(circuit, target)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ima/envs/qiskit/lib/python3.12/site-packages/qiskit_ibm_runtime/utils/utils.py", line 117, in is_isa_circuit
    return _is_isa_circuit_helper(circuit, target, qubit_map)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ima/envs/qiskit/lib/python3.12/site-packages/qiskit_ibm_runtime/utils/utils.py", line 79, in _is_isa_circuit_helper
    instruction.operation.params[0] < 0.0
TypeError: '<' not supported between instances of 'ParameterExpression' and 'float'

this PR

(no output)

This PR also removes redundant white spaces in the error message in the range [0, pi/2]. The full message is as follows.

qiskit_ibm_runtime.exceptions.IBMInputValueError: 'The instruction rzz on qubits (0, 1) is supported only for angles in the             range [0, pi/2], but an angle of 200.0 has been provided. Circuits that do not match the target hardware definition are no longer supported after March 4, 2024. See the transpilation documentation (https://docs.quantum.ibm.com/guides/transpile) for instructions to transform circuits and the primitive examples (https://docs.quantum.ibm.com/guides/primitives-examples) to see this coupled with operator transformations.'

Details and comments

Note that I think this PR needs to be merged to the server side too so that pubs with parameter expressions are processed without error.
E.g., cwrsqwf997wg008xfytg failed with the following error

Job not valid. '<' not supported between instances of 'ParameterExpression' and 'float'

Copy link
Collaborator

@yaelbh yaelbh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@t-imamichi Thanks a lot for the contribution! It's great, I wrote only one small comment.

qiskit_ibm_runtime/utils/utils.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@yaelbh yaelbh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I'll learn the consequences for #2021. But I'm curious: what made the second sub-test pass before the fix in ff75fe4?

@yaelbh
Copy link
Collaborator

yaelbh commented Nov 11, 2024

Note lint failure.

@t-imamichi
Copy link
Member Author

I forgot to remove the unnecessary import Parameter. I have fixed it just now. ff75fe4 simplified the second test by reusing the parameter p. So, it is essentially same as before.

@t-imamichi
Copy link
Member Author

Thank you for your review and comments, @yaelbh.

@yaelbh yaelbh merged commit aa393c9 into Qiskit:main Nov 11, 2024
19 checks passed
@t-imamichi t-imamichi deleted the fix-rzz-param branch November 11, 2024 09:16
@kt474 kt474 added Changelog: Bugfix Include in the Fixed section of the changelog backport potential The bug might be minimal and/or important enough to be port to stable labels Nov 11, 2024
kt474 pushed a commit that referenced this pull request Nov 11, 2024
* 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport potential The bug might be minimal and/or important enough to be port to stable Changelog: Bugfix Include in the Fixed section of the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants