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

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

Merged
merged 24 commits into from
Nov 27, 2023

Conversation

shef4
Copy link
Contributor

@shef4 shef4 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.

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

Copy link

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
@shef4 shef4 marked this pull request as ready for review November 17, 2023 00:02
@shef4 shef4 requested review from vtomole, cduck and a team as code owners November 17, 2023 00:02
@shef4 shef4 changed the title #6293_routcqc_stage_2 Break intermediate measurements on 3+ qubits into single qubit measurements in RouteCQC#6293 Nov 17, 2023
Copy link
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

cirq-core/cirq/transformers/routing/route_circuit_cqc.py Outdated Show resolved Hide resolved
cirq-core/cirq/transformers/routing/route_circuit_cqc.py Outdated Show resolved Hide resolved
cirq-core/cirq/transformers/routing/route_circuit_cqc.py Outdated Show resolved Hide resolved
cirq-core/cirq/transformers/routing/route_circuit_cqc.py Outdated Show resolved Hide resolved
updates from review- varible names, ciruit build
Copy link
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

Copy link
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
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
33 checks passed
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.

2 participants