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

OpenQASM 3 integer literals should use integer division #242

Closed
DanBlackwell opened this issue Apr 10, 2024 · 2 comments · Fixed by #247
Closed

OpenQASM 3 integer literals should use integer division #242

DanBlackwell opened this issue Apr 10, 2024 · 2 comments · Fixed by #247
Labels
bug Something isn't working

Comments

@DanBlackwell
Copy link

Describe the bug
After some discussion here: Qiskit/qiskit#12167, it seems that the stdgates.inc definition gate sx a { pow(1/2) @ x a; } should have the 1/2 resolve to 0 thanks to integer division (i.e. stdgates.inc has an incorrect definition of sx gate). As it stands, it seems that when interpreting openQASM 3, the Braket sim treats these values as floats (which makes that sx gate definition behave correctly). Apparently the relevant part of the specification is here: https://openqasm.com/language/classical.html#integers.

Being as 'fixing' this would break stdgates.inc as of right now, I don't think it should be 'fixed' yet. I'm not even sure how closely Braket promises to follow the openQASM specification, so perhaps it's a non-issue.

To reproduce

from braket.circuits import Circuit
from braket.devices import LocalSimulator

device = LocalSimulator()
quantum_circuit = Circuit.from_ir('''
OPENQASM 3.0;
include "stdgates.inc";
qubit[1] q;
ry(1/2) q;
''')
quantum_circuit.probability()
res = device.run(quantum_circuit, 0)
print(res.result().values)

Expected behavior
The ry(1/2) should resolve to ry(0) here resulting in a 1.0 probability of q being 0. To use floating point division it would need to be 1.0 / 2, 1 / 2.0 or 1.0 / 2.0.

Screenshots or logs
Actual output: [array([0.93879128, 0.06120872])]

System information
A description of your system. Please provide:

  • Amazon Braket Python SDK version: v1.74.0
  • Amazon Braket Python Schemas version:
  • Amazon Braket Python Default Simulator version:
  • Python version: Python 3.10.12

Additional context
N/A

@DanBlackwell DanBlackwell added the bug Something isn't working label Apr 10, 2024
@ashlhans
Copy link
Contributor

Hi @DanBlackwell - thank you for raising this issue! We will look into this.

@speller26 speller26 linked a pull request Apr 13, 2024 that will close this issue
5 tasks
@speller26
Copy link
Member

stdgates.inc will be fixed in openqasm/openqasm#529, so #247 will work fine with it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants