Skip to content

Commit 5293c55

Browse files
committed
revise syntax mismatches.
1 parent d09396d commit 5293c55

File tree

5 files changed

+81
-14
lines changed

5 files changed

+81
-14
lines changed

experiments/rabi.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import sys
2+
import os
3+
4+
# Add the directory containing your module to Python's search path
5+
module_path = ".."
6+
sys.path.insert(0, module_path)
7+
8+
from tensorcircuit import Circuit, Param, gates, waveforms
9+
from tensorcircuit.cloud.apis import submit_task, get_device, set_provider, set_token, list_devices
10+
import re
11+
12+
print("✅ TEST FILE LOADED")
13+
set_token("xu1LTrkf0nP6sI8oh.bDPdk35RlOQZYy9hQPU6jK2J4d5AdINAOszCNPxTNGZ3-opBPhWcLcruYuSrvX8is1D9tKgw-O4Zg.Qf7fLp83AtSPP19jD6Na4piICkygomdfyxIjzhO6Zu-s5hgBu2709ZW=")
14+
set_provider("tencent")
15+
ds = list_devices()
16+
print(ds)
17+
18+
def test_parametric_waveform():
19+
qc = Circuit(2)
20+
21+
param0 = Param("param0")
22+
param1 = Param("param1")
23+
24+
builder = qc.calibrate("my_gate", [param0, param1])
25+
builder.new_frame("f0", param0)
26+
builder.play("f0", waveforms.CosineDrag(10, 0.2, "0.5*PI", 0.01))
27+
builder.new_frame("f1", param1)
28+
builder.play("f1", waveforms.CosineDrag(20, 0.01, "0", 0))
29+
builder.build()
30+
31+
tqasm_code = qc.to_tqasm()
32+
tqasm_code = tqasm_code + '\nmygate q[0], q[1]'
33+
print(tqasm_code)
34+
35+
assert "TQASM 0.2;" in tqasm_code
36+
assert "defcal my_gate param0, param1" in tqasm_code
37+
assert "frame f0 = newframe(param0);" in tqasm_code
38+
assert "play(f0, cosine_drag(10, 0.2, 0.5*PI, 0.01));" in tqasm_code
39+
assert "frame f1 = newframe(param1);" in tqasm_code
40+
assert "play(f1, cosine_drag(20, 0.01, 0, 0));" in tqasm_code
41+
assert re.search(r"defcal my_gate [^\)]* \s*\{", tqasm_code)
42+
43+
44+
#tc.cloud.apis.set_token("xu1LTrkf0nP6sI8oh.bDPdk35RlOQZYy9hQPU6jK2J4d5AdINAOszCNPxTNGZ3-opBPhWcLcruYuSrvX8is1D9tKgw-O4Zg.Qf7fLp83AtSPP19jD6Na4piICkygomdfyxIjzhO6Zu-s5hgBu2709ZW=")
45+
#tc.cloud.apis.set_provider("tencent")
46+
device_name = "tianji_m2"
47+
d = get_device(device_name)
48+
t = submit_task(
49+
circuit=qc,
50+
shots=8192,
51+
device=d,
52+
enable_qos_gate_decomposition=False,
53+
enable_qos_qubit_mapping=False,
54+
)
55+
rf = t.results()
56+
print(rf)
57+
58+
59+
test_parametric_waveform()

tensorcircuit/backends/numpy_backend.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@ def imag(self, a: Tensor) -> Tensor:
214214

215215
def cast(self, a: Tensor, dtype: str) -> Tensor:
216216
with warnings.catch_warnings():
217-
warnings.simplefilter("ignore", np.ComplexWarning)
217+
#warnings.simplefilter("ignore", np.ComplexWarning)
218+
warnings.simplefilter("ignore", DeprecationWarning)
218219
if isinstance(dtype, str):
219220
return a.astype(getattr(np, dtype))
220221
return a.astype(dtype)

tensorcircuit/circuit.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ def add_calibration(
129129

130130
def to_tqasm(self) -> str:
131131
qasm_lines = []
132-
qasm_lines.append("OPENQASM 3;")
133-
qasm_lines.append(f"qubit[{self._nqubits}] q;")
132+
qasm_lines.append("TQASM 0.2;")
133+
qasm_lines.append(f"QREG q[{self._nqubits}];")
134134

135135
for gate in self._qir:
136136
gname = gate["name"]
@@ -139,7 +139,7 @@ def to_tqasm(self) -> str:
139139

140140
for cal in getattr(self, "calibrations", []):
141141
pname = ", ".join(cal["parameters"])
142-
qasm_lines.append(f"\ndefcal {cal['name']}({pname}) {{")
142+
qasm_lines.append(f"\ndefcal {cal['name']} {pname} {{")
143143
for inst in cal["instructions"]:
144144
if inst["type"] == "frame":
145145
qasm_lines.append(f" frame {inst['frame']} = newframe({inst['qubit']});")

tensorcircuit/cloud/tencent.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,9 @@ def c2qasm(c: Any, compiling: bool) -> str:
213213
s = c.qasm()
214214
# nq = c.num_qubits
215215
else:
216-
s = c.to_openqasm()
216+
s = c.to_tqasm() + '\nmy_gate q[0], q[1];'
217+
print(s)
218+
#s = c.to_openqasm()
217219
# nq = c._nqubits
218220
# s = _free_pi(s) # tQuk translation now supports this
219221
# if measure is not None: # ad hoc partial measurement

tests/test_parametric_waveform.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22
import os
33

44
# Add the directory containing your module to Python's search path
5-
module_path = "/Users/mac/tensorcircuit"
5+
module_path = ".."
66
sys.path.insert(0, module_path)
77

88
from tensorcircuit import Circuit, Param, gates, waveforms
9-
from tensorcircuit.cloud.apis import submit_task, get_device
9+
from tensorcircuit.cloud.apis import submit_task, get_device, set_provider, set_token, list_devices
1010
import re
1111

1212
print("✅ TEST FILE LOADED")
13+
set_token("xu1LTrkf0nP6sI8oh.bDPdk35RlOQZYy9hQPU6jK2J4d5AdINAOszCNPxTNGZ3-opBPhWcLcruYuSrvX8is1D9tKgw-O4Zg.Qf7fLp83AtSPP19jD6Na4piICkygomdfyxIjzhO6Zu-s5hgBu2709ZW=")
14+
set_provider("tencent")
15+
ds = list_devices()
16+
print(ds)
1317

1418
def test_parametric_waveform():
1519
qc = Circuit(2)
@@ -25,20 +29,21 @@ def test_parametric_waveform():
2529
builder.build()
2630

2731
tqasm_code = qc.to_tqasm()
32+
tqasm_code = tqasm_code + '\nmygate q[0], q[1]'
2833
print(tqasm_code)
2934

30-
assert "OPENQASM 3;" in tqasm_code
31-
assert "defcal my_gate(param0, param1)" in tqasm_code
35+
assert "TQASM 0.2;" in tqasm_code
36+
assert "defcal my_gate param0, param1" in tqasm_code
3237
assert "frame f0 = newframe(param0);" in tqasm_code
3338
assert "play(f0, cosine_drag(10, 0.2, 0.5*PI, 0.01));" in tqasm_code
3439
assert "frame f1 = newframe(param1);" in tqasm_code
3540
assert "play(f1, cosine_drag(20, 0.01, 0, 0));" in tqasm_code
36-
assert re.search(r"defcal my_gate\([^\)]*\)\s*\{", tqasm_code)
41+
assert re.search(r"defcal my_gate [^\)]* \s*\{", tqasm_code)
3742

38-
return
39-
40-
41-
device_name = "tianxuan_s1"
43+
44+
#tc.cloud.apis.set_token("xu1LTrkf0nP6sI8oh.bDPdk35RlOQZYy9hQPU6jK2J4d5AdINAOszCNPxTNGZ3-opBPhWcLcruYuSrvX8is1D9tKgw-O4Zg.Qf7fLp83AtSPP19jD6Na4piICkygomdfyxIjzhO6Zu-s5hgBu2709ZW=")
45+
#tc.cloud.apis.set_provider("tencent")
46+
device_name = "tianji_m2"
4247
d = get_device(device_name)
4348
t = submit_task(
4449
circuit=qc,

0 commit comments

Comments
 (0)