tequilahub / tequila

A High-Level Abstraction Framework for Quantum Algorithms

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

import_open_qasm import S gate error

andrew-koren opened this issue · comments

Describe the bug
Attempted to import multiple circuits from qasm, all circuits containing s gate failed to import.

TypeError: Phase() got multiple values for argument 'target'

The error message showed that this is due to part of parse_command() in qasm.py

if name in ("s", "t", "sdg", "tdg"):
        g = gates.Phase(pi / (2 if name.startswith("s") else 4),
                     control=None,
                     target=get_qregister(args[0], qregisters))
        if name.find("dg") != -1:
            g = g.dagger()
        return g

Changing this to

if name in ("s", "t", "sdg", "tdg"):
        g = gates.Phase(angle = pi / (2 if name.startswith("s") else 4),
                     control=None,
                     target=get_qregister(args[0], qregisters))
        if name.find("dg") != -1:
            g = g.dagger()
        return g

fixes the issue

To Reproduce
Steps to reproduce the behavior: Ideally an executable code snipped like

import tequila as tq

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*1.5,pi*2.0,0) q[0];\n\n// Gate: CZ**-1.0\nu3(pi*0.5,0,pi*1.25) q[0];\nu3(pi*0.5,pi*1.0,pi*1.75) q[1];\nsx q[0];\ncx q[0],q[1];\nrx(0) q[0];\nry(pi*0.5) q[1];\ncx q[1],q[0];\nsxdg q[1];\ns q[1];\ncx q[0],q[1];\nu3(pi*0.5,pi*1.25,pi*1.0) q[0];\nu3(pi*0.5,pi*0.75,0) q[1];\n\nu3(pi*0.5,pi*1.0,pi*0.5) q[0];\nu3(pi*1.7198391408,pi*1.5,pi*0.5) q[2];\nu3(pi*1.5,pi*1.1295046702,pi*0.8704953298) q[3];\ncz q[2],q[3];\nu3(pi*1.5,0,0) q[2];\nu3(pi*1.5,pi*1.1295046702,pi*0.8704953298) q[3];\ncz q[2],q[3];\nu3(pi*0.6295046702,0,pi*0.5) q[2];\nu3(pi*0.7198391408,pi*0.5,pi*1.3704953298) q[3];\n'
)

Expected behavior
Should import s gate without error

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~22.04.1-Ubuntu SMP Wed Jan 10 22:57:03 UTC 2024

Hi,

Thanks for the feedback. Since it appears that you have solved the issue already yourself, would you be interested in making a pull request to fix the issue? I usually prefer this, because the git log then credits you for solving.

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