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

Add a new gauge for SqrtCZ and support SqrtCZ† and fix and improve spin inversion gauge #6571

Merged
merged 11 commits into from
May 3, 2024

Conversation

NoureldinYosri
Copy link
Collaborator

No description provided.

Copy link
Collaborator

@eliottrosenberg eliottrosenberg left a comment

Choose a reason for hiding this comment

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

Thanks!

Copy link

codecov bot commented Apr 23, 2024

Codecov Report

Attention: Patch coverage is 97.87234% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 97.78%. Comparing base (614c78a) to head (02caccb).

Files Patch % Lines
...cirq/transformers/gauge_compiling/sqrt_cz_gauge.py 94.73% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6571      +/-   ##
==========================================
- Coverage   97.79%   97.78%   -0.01%     
==========================================
  Files        1124     1124              
  Lines       95659    95699      +40     
==========================================
+ Hits        93550    93580      +30     
- Misses       2109     2119      +10     

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

@NoureldinYosri NoureldinYosri marked this pull request as ready for review April 23, 2024 20:40
@NoureldinYosri NoureldinYosri requested review from vtomole, cduck and a team as code owners April 23, 2024 20:40
@NoureldinYosri NoureldinYosri requested a review from viathor April 23, 2024 20:40
@NoureldinYosri NoureldinYosri changed the title Add a new gauge for SqrtCZ Add a new gauge for SqrtCZ and support SqrtCZ† Apr 23, 2024
@eliottrosenberg eliottrosenberg self-requested a review April 24, 2024 15:26
Copy link
Collaborator

@eliottrosenberg eliottrosenberg left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks, Nour!!

Copy link
Collaborator

@pavoljuhas pavoljuhas left a comment

Choose a reason for hiding this comment

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

The swap_qubits field and logic seem unnecessary at this time.

return 5.0

def sample(self, gate: ops.Gate, prng: np.random.Generator) -> ConstantGauge:
if prng.choice([True, False]):
Copy link
Collaborator

Choose a reason for hiding this comment

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

If this can be called many times, consider using prng.integers(2) here and at other places.
prng.integers is about 5 times faster as it does not deal with a throw-away list.

@NoureldinYosri NoureldinYosri changed the title Add a new gauge for SqrtCZ and support SqrtCZ† Add a new gauge for SqrtCZ and support SqrtCZ† and fix and improve spin inversion gauge Apr 30, 2024
@NoureldinYosri
Copy link
Collaborator Author

@pavoljuhas when I use ops.CZ I get

cirq-core/cirq/transformers/gauge_compiling/sqrt_cz_gauge.py:28: error: Cannot determine type of "CZ"  [has-type]

@pavoljuhas
Copy link
Collaborator

@pavoljuhas when I use ops.CZ I get

cirq-core/cirq/transformers/gauge_compiling/sqrt_cz_gauge.py:28: error: Cannot determine type of "CZ"  [has-type]

This seems to happen because check/mypy cirq-core follows the import cirq loading order and that line is reached before the cirq.ops package is fully loaded. If gauge_compiling is not imported from transformers.__init__ the typecheck seems to pass.

Do we need to import gauge_compiling by default at import cirq or can it be an optional thing requiring import cirq.transformer.gauge_compiling to access?

If optional, we may save ourselves some headaches with circular imports or strange typechecking errors down the line.

Copy link
Collaborator

@pavoljuhas pavoljuhas left a comment

Choose a reason for hiding this comment

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

Few small tweaks, otherwise LGTM.

Comment on lines +35 to +37
class TestSpinInversionGauge_3(GaugeTester):
two_qubit_gate = cirq.ZZ**0.3
gauge_transformer = SpinInversionGaugeTransformer
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this test qualitatively different (ie testing different code paths) from TestSpinInversionGauge_1?
If not please remove.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this is a correctness test, making sure that the transformer works for all rotation angles. The reason that I create several is that I can't do pytest.mark.parametrize on the test class

this transfomer should work on Ising models where the strength of two qubit interactions g Z_i Z_j are encoded in the angels of ZZ(q[i], q[j])**g

post_q1=X,
post_q0=S if gate == _SQRT_CZ else _ADJ_S,
two_qubit_gate=gate**-1,
swap_qubits=True,
Copy link
Collaborator

Choose a reason for hiding this comment

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

A bit perplexed - the swap_qubits should have no effect as the gate**-1 will be symmetric for the q0, q1 swap.

@eliottrosenberg - is this functionality for simulation / execution of circuits that may have imperfect (ie asymmetric), SQRT_CZ, INV_SQRT_CZ gates?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

gauge compiling is done because the two qubit gate is assumed to be imperfect

@NoureldinYosri NoureldinYosri merged commit 3080d93 into quantumlib:main May 3, 2024
31 checks passed
@NoureldinYosri NoureldinYosri deleted the sqrt_cz_gauge branch May 3, 2024 14:48
migueltorrescosta pushed a commit to migueltorrescosta/Cirq that referenced this pull request May 3, 2024
jselig-rigetti pushed a commit to jselig-rigetti/Cirq that referenced this pull request May 28, 2024
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.

3 participants