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

master form_qasm() #140

Closed
Xuhongze opened this issue Mar 22, 2024 · 1 comment
Closed

master form_qasm() #140

Xuhongze opened this issue Mar 22, 2024 · 1 comment

Comments

@Xuhongze
Copy link

pq = QuantumCircuit(4)
theta = [Parameter("theta_%d" % (i), i + 1) for i in range(4)]
for i in range(4):
pq.rx(i, theta[i])
pq.rx(0, 55)
pq.ry(2, 4. * theta[0]+0.8)

pq.to_openqasm()
Out[8]: 'OPENQASM 2.0;\ninclude "qelib1.inc";\nqreg q[4];\ncreg meas[0];\nrx(2) q[0];\nrx(2) q[1];\nrx(2) q[2];\nrx(2) q[3];\nrx(55) q[0];\nry(8.8) q[2];\n'

qc.from_openqasm(pq.to_openqasm())
Traceback (most recent call last):
File "/Users/xhz/miniforge3/envs/quafumaster/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3577, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "", line 1, in
qc.from_openqasm(pq.to_openqasm())
File "/Users/xhz/miniforge3/envs/quafumaster/lib/python3.10/site-packages/pyquafu-0.4.0-py3.10-macosx-14.0-arm64.egg/quafu/circuits/quantum_circuit.py", line 483, in from_openqasm
return qasm2_to_quafu_qc(self, openqasm)
File "/Users/xhz/miniforge3/envs/quafumaster/lib/python3.10/site-packages/pyquafu-0.4.0-py3.10-macosx-14.0-arm64.egg/quafu/qfasm/qfasm_convertor.py", line 47, in qasm2_to_quafu_qc
newqc = qparser.parse(openqasm)
File "/Users/xhz/miniforge3/envs/quafumaster/lib/python3.10/site-packages/pyquafu-0.4.0-py3.10-macosx-14.0-arm64.egg/quafu/qfasm/qfasm_parser.py", line 100, in parse
self.parser.parse(data, lexer=self.lexer, debug=debug)
File "/Users/xhz/miniforge3/envs/quafumaster/lib/python3.10/site-packages/ply-3.11-py3.10.egg/ply/yacc.py", line 333, in parse
return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
File "/Users/xhz/miniforge3/envs/quafumaster/lib/python3.10/site-packages/ply-3.11-py3.10.egg/ply/yacc.py", line 1120, in parseopt_notrack
p.callable(pslice)
File "/Users/xhz/miniforge3/envs/quafumaster/lib/python3.10/site-packages/pyquafu-0.4.0-py3.10-macosx-14.0-arm64.egg/quafu/qfasm/qfasm_parser.py", line 1021, in p_cdecl
raise ParserError(
quafu.qfasm.exceptions.ParserError: CREG size must be positive at line 4 file None

@Zhaoyilunnn
Copy link
Collaborator

Zhaoyilunnn commented Apr 15, 2024

qasm="""OPENQASM 2.0;
include "qelib1.inc";
qreg q[130];
creg meas[130];
rz(0.9838363386329044) q[4];
rz(0.9121657461112626) q[3];
rz(0.3120104418951949) q[2];
ry(6.540656713831163e-05) q[4];
ry(-0.0019140855342319298) q[3];
ry(0.4649862690209438) q[2];
rz(0.7020529029150169) q[4];
rz(0.18602083244311104) q[3];
rz(0.01295780134509979) q[2];
cx q[4],q[3];
cx q[3],q[2];
rz(0.6026702349624573) q[4];
rz(-0.2037840707299793) q[3];
rz(-0.0548893490788779) q[2];
ry(-0.009123235869474786) q[4];
ry(-0.005734295834893282) q[3];
ry(-0.42163575674919446) q[2];
rz(0.37977281569008675) q[4];
rz(0.05611215332208219) q[3];
rz(0.33249617932043457) q[2];
cx q[4],q[3];
cx q[3],q[2];
rz(0.5176657346910741) q[4];
rz(-0.10944773003492535) q[3];
rz(0.21960804151816338) q[2];
ry(0.3315381464480086) q[4];
ry(0.01339410444054688) q[3];
ry(-0.05817454354796717) q[2];
rz(0.10420232101083632) q[4];
rz(0.8677074837561108) q[3];
rz(0.09368728039194918) q[2];
cx q[4],q[3];
cx q[3],q[2];
barrier q[2],q[3],q[4];
measure q[4] -> meas[0];
measure q[3] -> meas[1];
measure q[2] -> meas[2];"""

4c3c464b8412c2504b72f49d97026875_

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