Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f5e75c3

Browse files
author
v_anyuhe
committed
update
1 parent b0a1fc6 commit f5e75c3

File tree

5 files changed

+58
-54
lines changed

5 files changed

+58
-54
lines changed

‎tensorcircuit/__init__.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
from . import basecircuit
2727
from . import waveforms
2828
from .gates import Gate
29-
from .circuit import Circuit, expectation, Param
29+
from .circuit import Circuit, expectation
30+
from .pulse import Param
3031
from .mpscircuit import MPSCircuit
3132
from .densitymatrix import DMCircuit as DMCircuit_reference
3233
from .densitymatrix import DMCircuit2

‎tensorcircuit/circuit.py‎

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from .quantum import QuOperator, identity
1818
from .simplify import _full_light_cone_cancel
1919
from .basecircuit import BaseCircuit
20+
from .pulse import DefcalBuilder, Param, Frame
2021

2122
Gate = gates.Gate
2223
Tensor = Any
@@ -128,7 +129,7 @@ def def_calibration(
128129
})
129130

130131
def add_calibration(
131-
self, builder: "DefcalBuilder", parameters: List[str]
132+
self, builder: DefcalBuilder, parameters: List[str]
132133
) -> None:
133134
self.calibration_invokes.append({
134135
"name": builder.name,
@@ -1084,51 +1085,3 @@ def expectation(
10841085
else:
10851086
den = 1.0
10861087
return num / den
1087-
1088-
class Param:
1089-
def __init__(self, name: str):
1090-
self.name = name
1091-
1092-
class Frame:
1093-
def __init__(self, name: str):
1094-
self.name = name
1095-
1096-
class DefcalBuilder:
1097-
def __init__(self, circuit, name: str, parameters: List["Param"]):
1098-
self.circuit = circuit
1099-
self.name = name
1100-
self.parameters = parameters
1101-
self.instructions = []
1102-
1103-
def new_frame(self, frame_name: str, param: "Param"):
1104-
frame = Frame(frame_name)
1105-
self.instructions.append({
1106-
"type": "frame",
1107-
"frame": frame,
1108-
"qubit": param.name,
1109-
})
1110-
return frame
1111-
1112-
def play(self, frame: Frame, waveform: Any, start_time: int = None):
1113-
if not hasattr(waveform, "__dataclass_fields__"):
1114-
raise TypeError("Unsupported waveform type")
1115-
1116-
waveform_type = waveform.qasm_name()
1117-
args = waveform.to_args()
1118-
if start_time is not None:
1119-
args = [start_time] + args
1120-
1121-
self.instructions.append({
1122-
"type": "play",
1123-
"frame": frame.name,
1124-
"waveform_type": waveform_type,
1125-
"args": args,
1126-
})
1127-
return self
1128-
1129-
def build(self):
1130-
self.circuit.def_calibration(
1131-
name=self.name,
1132-
parameters=[p.name for p in self.parameters],
1133-
instructions=self.instructions,
1134-
)

‎tensorcircuit/cloud/tencent.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def update_pairs(user_addr1: int, user_addr2: int, add_remove: bool = True):
7878
update_pairs(user_addr2, user_addr1, add_remove)
7979
return
8080

81-
def pragmam(self) -> str:
81+
def pragma(self) -> str:
8282
lines = []
8383
if self._used_chip_qubits == [] or self._used_user_qubits == []:
8484
return None
@@ -297,9 +297,8 @@ def c2qasm(c: Any, compiling: bool) -> str:
297297
else:
298298
prag = None
299299
if topology is not None:
300-
prag = topology.pragmam()
300+
prag = topology.pragma()
301301
s = c.to_tqasm(prag)
302-
print(s)
303302
lang = "TQASM"
304303
#s = c.to_openqasm()
305304
# nq = c._nqubits

‎tensorcircuit/pulse.py‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from typing import List, Dict, Any
2+
3+
4+
class Param:
5+
def __init__(self, name: str):
6+
self.name = name
7+
8+
class Frame:
9+
def __init__(self, name: str):
10+
self.name = name
11+
12+
class DefcalBuilder:
13+
def __init__(self, circuit, name: str, parameters: List["Param"]):
14+
self.circuit = circuit
15+
self.name = name
16+
self.parameters = parameters
17+
self.instructions = []
18+
19+
def new_frame(self, frame_name: str, param: "Param"):
20+
frame = Frame(frame_name)
21+
self.instructions.append({
22+
"type": "frame",
23+
"frame": frame,
24+
"qubit": param.name,
25+
})
26+
return frame
27+
28+
def play(self, frame: Frame, waveform: Any, start_time: int = None):
29+
if not hasattr(waveform, "__dataclass_fields__"):
30+
raise TypeError("Unsupported waveform type")
31+
32+
waveform_type = waveform.qasm_name()
33+
args = waveform.to_args()
34+
if start_time is not None:
35+
args = [start_time] + args
36+
37+
self.instructions.append({
38+
"type": "play",
39+
"frame": frame.name,
40+
"waveform_type": waveform_type,
41+
"args": args,
42+
})
43+
return self
44+
45+
def build(self):
46+
self.circuit.def_calibration(
47+
name=self.name,
48+
parameters=[p.name for p in self.parameters],
49+
instructions=self.instructions,
50+
)

‎tests/04_test_custom_chip.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323
print(ds)
2424

2525
def gen_custom_chip_circuit(t):
26-
qc = Circuit(2)
26+
qc = Circuit(3)
2727

28+
# qc.h(0)
2829
qc.cnot(0, 2)
2930
# qc.cnot(1, 3)
3031
# qc.cnot(0, 3)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /