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

support output assignment for function calls #70

Merged
merged 3 commits into from
Sep 25, 2023

Conversation

yitchen-tim
Copy link
Contributor

closes: #69

Description of change:
Support optional output assignment for oqpy.function_call

@yitchen-tim yitchen-tim marked this pull request as ready for review September 17, 2023 16:39
@PhilReinhold
Copy link
Collaborator

So there are a few existing options for this. I think the "most correct" way is to use an extern, i.e.

my_function = oqpy.declare_extern("my_function", [], oqpy.bit)
b = oqpy.BitVar(name="b")
prog.set(b, my_function())

If you really don't want the extern statement to be added you can say "include_externs=False" when generating the program.

You could also do this without creating an extern via prog.set(b, oqpy.OQFunctionCall("my_function", [], oqpy.bit)).

That being said, maybe it is just easier to add this extra code to allow another way of doing it.

@yitchen-tim
Copy link
Contributor Author

thanks for the suggestion! A follow up question: what is the purpose for program.function_call? I assume it's for calling build in functions without first defining them like externs. In the future, if a oqpy built-in function call requires return values, doesn't oqpy still need to implement this PR?

@PhilReinhold
Copy link
Collaborator

thanks for the suggestion! A follow up question: what is the purpose for program.function_call?

It is an escape hatch to allow manual workaround, it shouldn't be required in normal operation, but yes I think as long as we have it, we should allow it to assign to variables, so I think this change is good. On second look, I don't have any requested changes, so I think we can just merge this, sorry for the perhaps unnecessary delay.

@PhilReinhold PhilReinhold merged commit f0885b7 into openqasm:main Sep 25, 2023
@yitchen-tim
Copy link
Contributor Author

yitchen-tim commented Sep 25, 2023

Understood. I think the corner cases that require using function call but not extern would be someone want to make a function call without producing an extern statement in OpenQASM script, but they want to use include_externs=True for other extern statements.

@yitchen-tim yitchen-tim deleted the function-call-assignment branch September 25, 2023 16:03
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.

support function calls with return assignments
2 participants