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

Z gate .dagger failed #333

Closed
andrew-koren opened this issue Mar 12, 2024 · 4 comments
Closed

Z gate .dagger failed #333

andrew-koren opened this issue Mar 12, 2024 · 4 comments

Comments

@andrew-koren
Copy link

Describe the bug
After importing openqasm circuit to tequila using tq.import_open_qasm(), the hermitian conjugate of the circuit containing the gate Z(target=(1,), control=(0,)) could not be found. The hermeitian conjugate of this gate could not be calculated using .dagger(). In addition, this gate has no generator.

To Reproduce

import tequila as tq

imported_circuit = tq.import_open_qasm('// Generated from Cirq v1.3.0\n\nOPENQASM 2.0;\ninclude "qelib1.inc";\n\n\n// Qubits: [q(0), q(1), q(2), q(3)]\nqreg q[4];\n\n\nu3(pi*0.5,pi*1.25,pi*0.75) q[0];\nu3(pi*0.25,pi*1.5,pi*0.5) q[1];\ncz q[0],q[1];\nu3(pi*1.5,pi*1.25,pi*0.75) q[0];\nu3(pi*0.5,0,0) q[1];\ncz q[0],q[1];\nu3(pi*0.25,pi*0.5,pi*0.25) q[0];\nu3(pi*0.5,pi*1.25,pi*1.0) q[1];\nu3(pi*0.5,pi*1.25,pi*0.75) q[2];\nu3(pi*0.25,pi*1.5,pi*0.5) q[3];\ncz q[2],q[3];\nu3(pi*1.5,pi*1.25,pi*0.75) q[2];\nu3(pi*0.5,0,0) q[3];\ncz q[2],q[3];\nu3(pi*0.25,pi*0.5,pi*0.25) q[2];\nu3(pi*0.5,pi*1.25,pi*1.0) q[3];\n')
#imported_circuit.dagger()

for gate in imported_circuit.gates:
    print(gate)
    print(gate.generator)
    print(gate.dagger())

Expected behavior
Imported circuit hermetian conjugate should be returned

Computer (please complete the following information):
tequila version: 1.9.4
python version: 3.10.13 (main, Feb 6 2024, 19:53:26) [GCC 9.4.0]
platform: #19 SMP Wed Jan 10 22:57:03 UTC 2024

@kottmanj
Copy link
Collaborator

kottmanj commented Mar 13, 2024

Thanks for noticing.

I think I know the underlying issue, it's basically because the open-qasm import module uses calls to low-level functions to initialize gates:
Example:

gates.impl.QGateImpl(....)

instead of

gates.Z(....)

In principle all gates.impl.XYimpl(name=NAME,....) calls in the function parse_command in the file src/tequila/circuit/qasm.py need to be replaced by the corresponding gates.NAME(...) call.

All initialization routines in tq.gates will set generators correctly.
(generators for all gates where introduced after the open-qasm module)

In principle not hard to fix, but will need a bit of time due to other things.

@kottmanj
Copy link
Collaborator

Feel free to do a PR if you are interested in fixing it yourself :-)
Otherwise I try to get it done by the end of march

kottmanj added a commit that referenced this issue Mar 18, 2024
Fixes issue #333
@kottmanj
Copy link
Collaborator

Should work now. Please let me know if not. Tanks for reporting!

@andrew-koren
Copy link
Author

Success! I was able to verify this works, along with import S gate

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

No branches or pull requests

2 participants