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

Promote floats to durations during arithmetic ops #42

Merged

Conversation

anuragm
Copy link
Contributor

@anuragm anuragm commented May 25, 2023

oqpy allows adding float literals to durations, but they are not automatically converted to duration literals (unlike initialization of DurationVar or duration arrays, where python floating literals are automatically converted to duration literals).

With this change, literals are automatically promoted. For example,

prog = oqpy.Program()
port = oqpy.PortVar(name="my_port")
frame = oqpy.FrameVar(name="my_frame", port=port, frequency=5e9, phase=0)

prog.delay(delay + 5e-9, frame)
print(prog.to_qasm(encal_declarations=True))

will correctly promote 5e-9 to a duration literal and output

OPENQASM 3.0;
defcalgrammar "openpulse";
cal {
    port my_port;
    frame my_frame = newframe(my_port, 5000000000.0, 0);
}
duration d = 10.0ns;
delay[d + 5.0ns] my_frame;

Copy link
Collaborator

@PhilReinhold PhilReinhold left a comment

Choose a reason for hiding this comment

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

Small comments but otherwise looks good

oqpy/base.py Show resolved Hide resolved
oqpy/base.py Show resolved Hide resolved
@anuragm anuragm requested a review from PhilReinhold May 25, 2023 19:17
@jcjaskula-aws jcjaskula-aws merged commit bb4cbe3 into openqasm:main May 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants