-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Allow passing None
to AbstractCircuit.from_moments
#6637
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #6637 +/- ##
=======================================
Coverage 97.81% 97.81%
=======================================
Files 1067 1067
Lines 91550 91551 +1
=======================================
+ Hits 89549 89550 +1
Misses 2001 2001 ☔ View full report in Codecov by Sentry. |
for m in moments: | ||
if isinstance(m, Moment): | ||
yield m | ||
elif isinstance(m, AbstractCircuit): | ||
yield Moment(m.freeze().to_op()) | ||
else: | ||
elif m is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be elif m
to encapsulate the empty []
case as well? Since None
is expected to replace the []
case, I'd expect them to yield the same output. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't intend for None
to replace []
. The former would be skipped, while the latter would produce an empty moment in the circuit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for clarifying!
for m in moments: | ||
if isinstance(m, Moment): | ||
yield m | ||
elif isinstance(m, AbstractCircuit): | ||
yield Moment(m.freeze().to_op()) | ||
else: | ||
elif m is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for clarifying!
When constructing circuits with
Circuit.from_moments
we often want to conditionally include a moment and we often end up with awkward expressions like:This PR would allow us to pass
None
as an arg tofrom_moments
in which case that arg would be skipped and not included in the circuit (not even as an empty moment). The above code can then be written more clearly as: