Skip to content

Break intermediate measurements on 3+ qubits into single qubit measurements in RouteCQC#6293#6349

Merged
NoureldinYosri merged 24 commits intomasterfrom
unknown repository
Nov 27, 2023
Merged

Break intermediate measurements on 3+ qubits into single qubit measurements in RouteCQC#6293#6349
NoureldinYosri merged 24 commits intomasterfrom
unknown repository

Conversation

@ghost
Copy link
Copy Markdown

@ghost ghost commented Nov 16, 2023

router mishandling mid-circuit measurements #issue6293

Description of the issue

cirq.RouteCQC commutes gates in undefined ways due to intermediate measurements with 3 or more qubits not being handled correctly.

This PR aims to fix this issue by:

Breaking intermediate measurements on 3+ qubits into single qubit measurements if the result isn't stored (i.e. key is None) else a ValueError is raised.

Next Steps

Check if it's possible to create a ClassicallyControlledOperation controlled by the result of a multiqubit measurement

cirq.ClassicallyControlledOperation(
    sub_operation: 'cirq.Operation',
    conditions: Sequence[Union[str, 'cirq.MeasurementKey', 'cirq.Condition', sympy.Basic]]
)

From looking at the documentation it seems to be possible. Will stop here until there is a need to support this case.

@review-notebook-app
Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@codecov
Copy link
Copy Markdown

codecov bot commented Nov 16, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (b5b3b74) 97.84% compared to head (93a06f6) 97.84%.
Report is 1 commits behind head on master.

❗ Current head 93a06f6 differs from pull request most recent head 7a03d0c. Consider uploading reports for the commit 7a03d0c to get more accurate results

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #6349   +/-   ##
=======================================
  Coverage   97.84%   97.84%           
=======================================
  Files        1110     1110           
  Lines       96690    96706   +16     
=======================================
+ Hits        94606    94622   +16     
  Misses       2084     2084           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

on 3+ qubits into single qubit measurements
if -and only if- the result isn't stored (i.e. key is None)
and test for changes in RoutCQC
@ghost ghost marked this pull request as ready for review November 17, 2023 00:02
@ghost ghost requested review from a team, cduck and vtomole as code owners November 17, 2023 00:02
@ghost ghost requested a review from 95-martin-orion November 17, 2023 00:02
@ghost ghost changed the title #6293_routcqc_stage_2 Break intermediate measurements on 3+ qubits into single qubit measurements in RouteCQC#6293 Nov 17, 2023
Comment thread docs/transform/routing_transformer.ipynb Outdated
Copy link
Copy Markdown
Collaborator

@NoureldinYosri NoureldinYosri left a comment

Choose a reason for hiding this comment

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

please remove changes to unrelated files

Comment thread cirq-core/cirq/transformers/routing/route_circuit_cqc_test.py Outdated
Comment thread cirq-core/cirq/transformers/routing/route_circuit_cqc.py Outdated
Comment thread cirq-core/cirq/transformers/routing/route_circuit_cqc.py Outdated
Comment thread cirq-core/cirq/transformers/routing/route_circuit_cqc.py Outdated
Comment thread cirq-core/cirq/transformers/routing/route_circuit_cqc.py Outdated
Comment thread cirq-core/cirq/transformers/routing/route_circuit_cqc_test.py Outdated
Comment thread cirq-core/cirq/transformers/routing/route_circuit_cqc.py Outdated
Comment thread cirq-core/cirq/transformers/routing/route_circuit_cqc_test.py Outdated
Comment thread cirq-core/cirq/transformers/routing/route_circuit_cqc_test.py Outdated
Comment thread cirq-core/cirq/transformers/routing/route_circuit_cqc_test.py Outdated
Comment thread docs/transform/routing_transformer.ipynb Outdated
updates from review- varible names, ciruit build
Comment thread cirq-core/cirq/transformers/routing/route_circuit_cqc.py Outdated
Copy link
Copy Markdown
Collaborator

@NoureldinYosri NoureldinYosri left a comment

Choose a reason for hiding this comment

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

just a few more nits + please fix the conflict with the main branch

Comment thread cirq-core/cirq/transformers/routing/route_circuit_cqc_test.py Outdated
Comment thread cirq-core/cirq/transformers/routing/route_circuit_cqc.py Outdated
Comment thread cirq-core/cirq/transformers/routing/route_circuit_cqc.py Outdated
Copy link
Copy Markdown
Collaborator

@NoureldinYosri NoureldinYosri left a comment

Choose a reason for hiding this comment

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

almost there. one small change

operation = (
'Intermediate measurements on three or more qubits with a custom key'
)
raise ValueError(f'Unsupported operation: {operation}')
Copy link
Copy Markdown
Collaborator

@NoureldinYosri NoureldinYosri Nov 27, 2023

Choose a reason for hiding this comment

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

raise ValueError('Intermediate measurements on three or more qubits with a custom key are not supported')

if this line is too long you can break it into two string literals

raise ValueError('Intermediate measurements on three or more qubits '
                           'with a custom key are not supported')

@NoureldinYosri NoureldinYosri enabled auto-merge (squash) November 27, 2023 20:52
@NoureldinYosri NoureldinYosri merged commit a4ba95b into quantumlib:master Nov 27, 2023
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this pull request Oct 31, 2024
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.

1 participant