Support merging 1-qubit gates in transformers for parameterized circuits#7149
Support merging 1-qubit gates in transformers for parameterized circuits#7149babacry wants to merge 19 commits intoquantumlib:mainfrom
Conversation
3dea74b to
d5da63a
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #7149 +/- ##
========================================
Coverage 98.66% 98.67%
========================================
Files 1106 1110 +4
Lines 96086 96266 +180
========================================
+ Hits 94808 94987 +179
- Misses 1278 1279 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Hi Eliott, Nour, I have added the function to support one use case. Could you PTAL? For the use case of combined input of sweep and parameterized circuit, will be added in the followup PR. Let's first make sure this PR is in the right place and do the right job. Thanks! |
eliottrosenberg
left a comment
There was a problem hiding this comment.
I tested it a little bit in this colab, and it doesn't seem to work properly yet, the interface looks good to me.
|
One small comment: it would be nice if the merged single-qubit gates ended up in the same moment; see this cell of the colab. |
|
Got you, thanks a lot for the manual checks! I will update the pr accordingly and fix checks. |
33a8233 to
7ac61a5
Compare
tag_transformers: remove_tags, index_tags. symbolize: symbolize_single_qubit_gates_by_indexed_tags
|
Thanks Nour for the valuable suggestions. I come up with a much better version with your inputs. @NoureldinYosri I added Could you help take another look? (I can split the tag_transformer, symbolize transformers out in different prs if this PR is too huge). |
NoureldinYosri
left a comment
There was a problem hiding this comment.
lets split this PR into smaller PRs ... also what is happening with all these tags?
| circuit: 'cirq.AbstractCircuit', | ||
| *, | ||
| context: Optional['cirq.TransformerContext'] = None, | ||
| merge_tags_fn: Optional[Callable[['cirq.CircuitOperation'], List[Hashable]]] = None, |
There was a problem hiding this comment.
I feel like this is a bit too general ... what is the problem with recieving a list of tags ?
There was a problem hiding this comment.
I kind of need a function here as what I need to do is given a circuit op, set the output tags with more rule based tag setters and I believe the flexibility of the function can help users in different use cases.
- Currently, the merge function do the following mapping in the
rewriter
CircuitOperation(X['tag_needed'] -- Y['tag1']) --> phxz(x,z,a) with no tags
- In my use case, I need a rule based tag setter:
case 1: CircuitOperation(X['tag_needed'] -- Y['tag1']) --'tag_needed' presented--> phxz(...)['phxz_{iter}']
case 2: CircuitOperation(X -- Z) --no 'tags_needed' found --> phxz(...) with no tags
- Flexibility of merge_tags_fn: e.g., if users want to preserve all the tags in the circuit op, they may do the merges in merge_tags_fn, then the tags can preserve like the following
CircuitOperation(X['tag0'] -- Y['tag1']) --> phxz(...)['tag0', 'tag1']
| ) | ||
| merged_circuits.append(merged_circuit) | ||
|
|
||
| if not all( |
There was a problem hiding this comment.
I don't think this should happen here ... this should be a test for the correctness of the transformer
There was a problem hiding this comment.
It's to validate the input parameters sweep, basically all the resolvers in sweep shoulld resolve the circuit to the same structure, otherwise, we can't do the merge here.
If we don't check here, Step 2 of parameterization would possibly crash with different kind of errors.
I should probably update the error message as InvalidArgument("Invalid input sweep, different resolvers in sweep resulted in different merged structures.")
|
Thanks! @NoureldinYosri I will split the PRs =) |
|
@babacry Are the 2 new PRs complete replacements for this one? If so, should this one be closed? |
|
@mhucka this pr will depend on the other 2 prs. Though this PR is too noisy right now and out of sync, I will close this one and create a new PR with this closed pr attached. FYI @NoureldinYosri @eliottrosenberg . |
|
@babacry Ok, thank you! |
Merge single qubit gates for symbolized circuits. It is a updated version of #7149 where tag_transformers and symbolize transformers are already merged. --------- Co-authored-by: eliottrosenberg <61400172+eliottrosenberg@users.noreply.github.com>
Merge single qubit gates for symbolized circuits. It is a updated version of #7149 where tag_transformers and symbolize transformers are already merged. --------- Co-authored-by: eliottrosenberg <61400172+eliottrosenberg@users.noreply.github.com>
Merge single qubit gates for symbolized circuits. It is a updated version of quantumlib#7149 where tag_transformers and symbolize transformers are already merged. --------- Co-authored-by: eliottrosenberg <61400172+eliottrosenberg@users.noreply.github.com>
Merge single qubit gates for symbolized circuits. It is a updated version of quantumlib#7149 where tag_transformers and symbolize transformers are already merged. --------- Co-authored-by: eliottrosenberg <61400172+eliottrosenberg@users.noreply.github.com>
Input: symbolized_circuit, sweep
Output: new_symbolzied_circuit, new_sweep