Skip to content

Allow for loops with arbitrary variable type #26

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

Merged
merged 5 commits into from
Feb 27, 2023

Conversation

anuragm
Copy link
Contributor

@anuragm anuragm commented Feb 21, 2023

This pull request enables for loops over arbitrary kinds of arrays. For example, one might desire to loop over some float value. This can be done using the following snippet:

import oqpy

program = oqpy.Program()
port = oqpy.PortVar("my_port")
frame = oqpy.FrameVar(port, 3e9, 0, "my_frame")

frequencies = [0.1, 0.2, 0.5]
with oqpy.ForIn(program, frequencies, "frequency", oqpy.FloatVar) as f:
    program.set_frequency(frame, f)

which outputs the following QASM program:

OPENQASM 3.0;
port my_port;
frame my_frame = newframe(my_port, 3000000000.0, 0);
for float frequency in {0.1, 0.2, 0.5} {
  set_frequency(my_frame, frequency);
}

@CLAassistant
Copy link

CLAassistant commented Feb 21, 2023

CLA assistant check
All committers have signed the CLA.

@anuragm anuragm requested review from PhilReinhold and jcjaskula-aws and removed request for PhilReinhold and jcjaskula-aws February 24, 2023 23:01
@PhilReinhold
Copy link
Collaborator

Looks good to me. I'll leave it to @jcjaskula-aws to merge after final approval

Copy link
Collaborator

@jcjaskula-aws jcjaskula-aws left a comment

Choose a reason for hiding this comment

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

After giving more thoughts about it, it looks good to me. Approving. Thanks for helping.

@jcjaskula-aws jcjaskula-aws merged commit dd99778 into openqasm:main Feb 27, 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.

4 participants