Skip to content

Commit ba1daad

Browse files
committed
make compatible of original visualize function.
1 parent 92ce79a commit ba1daad

File tree

5 files changed

+18
-6
lines changed

5 files changed

+18
-6
lines changed

tensorcircuit/abstractcircuit.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class AbstractCircuit:
7878
vgates = vgates
7979
mpogates = mpogates
8080
gate_aliases = gate_aliases
81+
__is_openqasm = True
8182

8283
def __init__(self, nqubits: int, *args, **kwargs):
8384
self._nqubits = nqubits
@@ -101,6 +102,12 @@ def apply_general_gate(
101102
"""
102103
raise NotImplementedError
103104

105+
def disable_openqasm(self):
106+
self.__is_openqasm = False
107+
108+
def is_openqasm(self):
109+
return self.__is_openqasm
110+
104111
@staticmethod
105112
def apply_general_variable_gate_delayed(
106113
gatef: Callable[..., Gate],

tensorcircuit/circuit.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,15 @@ def def_calibration(
132132
def add_calibration(
133133
self, builder: DefcalBuilder, parameters: List[str]
134134
) -> None:
135+
self.disable_openqasm()
135136
self.calibration_invokes.append({
136137
"name": builder.name,
137138
"parameters": parameters,
138139
"pos": len(self._qir)
139140
})
140141

141142
def measz(self, *index: int) -> None:
143+
self.disable_openqasm()
142144
self.measz_invokes.append({
143145
"name": "measz",
144146
"index": index,

tensorcircuit/cloud/tencent.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,13 @@ def c2qasm(c: Any, compiling: bool) -> str:
296296
prag = None
297297
if topology is not None:
298298
prag = topology.pragma()
299-
s = c.to_tqasm(prag)
300-
lang = "TQASM"
299+
300+
if c.is_openqasm() and topology is None:
301+
lang = "OPENQASM"
302+
s = c.to_openqasm()
303+
else:
304+
lang = "TQASM"
305+
s = c.to_tqasm(prag)
301306
#s = c.to_openqasm()
302307
# nq = c._nqubits
303308
# s = _free_pi(s) # tQuk translation now supports this

tests/01_test_gate.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ def gen_gate_circuit(t):
2727
qc.h(0)
2828
qc.cnot(0, 1)
2929

30-
print(qc.to_tqasm())
31-
3230
return qc
3331

3432

@@ -45,7 +43,7 @@ def run_circuit(qc):
4543
# print(qc.to_tqasm())
4644
# n = qc._nqubits
4745
rf = t.results()
48-
# print(rf)
46+
t.details(prettify=True)["backend"].draw(output="mpl")
4947
return rf
5048

5149
qc = gen_gate_circuit(1.0)

tests/02_test_param_pulse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def run_circuit(qc):
6565
rf = t.results()
6666
# print(rf)
6767

68-
t.details(prettify=True)
68+
6969
return rf
7070

7171
qc = gen_parametric_waveform_circuit(1.0)

0 commit comments

Comments
 (0)