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

Support inverse gate JSON seralization #6912

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

justinpan0
Copy link

Response to issue #6769

Fix validation

Running the code snippet provided in #6769 now yields correct result:

0: ───[0>0]──────
      │
1: ───[1>1]──────
      │
2: ───[2>2]^-1───
{
  "cirq_type": "Circuit",
  "moments": [
    {
      "cirq_type": "Moment",
      "operations": [
        {
          "cirq_type": "GateOperation",
          "gate": {
            "cirq_type": "_InverseCompositeGate",
            "val": {
              "cirq_type": "QubitPermutationGate",
              "permutation": [
                0,
                1,
                2
              ]
            }
          },
          "qubits": [
            {
              "cirq_type": "LineQubit",
              "x": 0
            },
            {
              "cirq_type": "LineQubit",
              "x": 1
            },
            {
              "cirq_type": "LineQubit",
              "x": 2
            }
          ]
        }
      ]
    }
  ]
}
0: ───[0>0]──────
      │
1: ───[1>1]──────
      │
2: ───[2>2]^-1───

@justinpan0 justinpan0 requested review from vtomole and a team as code owners January 3, 2025 07:06
@justinpan0 justinpan0 requested a review from senecameeks January 3, 2025 07:06
@CirqBot CirqBot added the size: S 10< lines changed <50 label Jan 3, 2025
Copy link

codecov bot commented Jan 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.86%. Comparing base (83a8e0e) to head (1ce0c5d).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6912   +/-   ##
=======================================
  Coverage   97.86%   97.86%           
=======================================
  Files        1084     1084           
  Lines       94290    94293    +3     
=======================================
+ Hits        92280    92283    +3     
  Misses       2010     2010           

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

@@ -281,4 +281,5 @@ def _symmetricalqidpair(qids):
'sympy.EulerGamma': lambda: sympy.EulerGamma,
'complex': complex,
'datetime.datetime': _datetime,
'_InverseCompositeGate': cirq.inverse,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a reason this is calling cirq.inverse vs instantiating the _InverseCompositeGate class? I am not sure which is better.

I guess if we created an inverse for a gate in a newer version of cirq, it could instantiate that instead, which would not be consistent object-wise, but might be a better result? For instance, we could fix this so QubitPermutationGate(0,1,2) ^ -1 returns QubitPermutationGate(2,1,0) or whatever.

In any case, maybe add a comment to explain the behaviour.

Copy link
Collaborator

@dstrain115 dstrain115 left a comment

Choose a reason for hiding this comment

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

LGTM pending one comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: S 10< lines changed <50
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants