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

Inverting gates does not allow to save circuit in json #6538

Open
nikita-astronaut opened this issue Apr 1, 2024 · 3 comments
Open

Inverting gates does not allow to save circuit in json #6538

nikita-astronaut opened this issue Apr 1, 2024 · 3 comments
Assignees
Labels
kind/bug-report Something doesn't seem to work. triage/accepted there is consensus amongst maintainers that this is a real bug or a reasonable feature to add

Comments

@nikita-astronaut
Copy link

nikita-astronaut commented Apr 1, 2024

Description of the issue

How to reproduce the issue


U = cirq.Circuit()
K = cirq.Circuit()
K.append(cirq.PhasedFSimGate(0, 0, 0, 0,0).on(cirq.GridQubit(0, 0), cirq.GridQubit(0, 1)))

U.append(K)
U.append(cirq.X.on(cirq.GridQubit(0, 0)))
U.append(cirq.inverse(K))


with open('test.json', 'wb') as f:
    f.write(cirq.to_json(U).encode('utf-8'))
    f.close()

U = cirq.read_json(open('test.json', 'rb'))

---> the following code will fail with:

ValueError: Could not resolve type '_InverseCompositeGate' during deserialization

Cirq version

1.2.0
@nikita-astronaut nikita-astronaut added the kind/bug-report Something doesn't seem to work. label Apr 1, 2024
@tanujkhattar
Copy link
Collaborator

I'm surprised this is the case!

@pavoljuhas Can you please take a look?

@pavoljuhas
Copy link
Collaborator

@tanujkhattar - this can be reduced to the serialization of an inverted cirq.PhasedFSimGate, which ends up as follows -

>>> print(cirq.to_json(cirq.inverse(cirq.PhasedFSimGate(0))).replace("\\n", "\n"))
{
  "cirq_type": "_InverseCompositeGate"
}

_InverseCompositeGate does not have its own _json_dict_ method so there is no information on what is inverted.

After a quick search through the git history I could not find any tests of _InverseCompositeGate serialization, and its underscored name suggests it is a non-public class.

I wonder why was the serialization omitted for _ICG.
Would you know of more of a context there?

cc: @Strilanc

@tanujkhattar
Copy link
Collaborator

tanujkhattar commented Apr 2, 2024

There may not be any specific reason;

I think we should go ahead and add _json_dict_ to the gate. We should also consider making _InverseCompositeGate a public gate (and rename it to Adjoint)

@dstrain115 dstrain115 added the triage/discuss Needs decision / discussion, bring these up during Cirq Cynque label Apr 4, 2024
@verult verult added triage/accepted there is consensus amongst maintainers that this is a real bug or a reasonable feature to add and removed triage/discuss Needs decision / discussion, bring these up during Cirq Cynque labels Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug-report Something doesn't seem to work. triage/accepted there is consensus amongst maintainers that this is a real bug or a reasonable feature to add
Projects
None yet
Development

No branches or pull requests

5 participants