Skip to content

Commit cc8e3ee

Browse files
authored
Update circuit.py
1 parent 001136b commit cc8e3ee

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

tensorcircuit/circuit.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def __init__(
6464
nqubits=nqubits, inputs=inputs, mps_inputs=mps_inputs, split=split
6565
)
6666
self.calibrations = []
67+
self.calibration_invokes = []
6768

6869
self.inputs = inputs
6970
self.mps_inputs = mps_inputs
@@ -117,7 +118,7 @@ def __init__(
117118
self._qir: List[Dict[str, Any]] = []
118119
self._extra_qir: List[Dict[str, Any]] = []
119120

120-
def add_calibration(
121+
def def_calibration(
121122
self, name: str, parameters: List[str], instructions: List[Dict]
122123
) -> None:
123124
self.calibrations.append({
@@ -126,6 +127,15 @@ def add_calibration(
126127
"instructions": instructions
127128
})
128129

130+
def add_calibration(
131+
self, name: str, parameters: List[str], instructions: List[Dict]
132+
) -> None:
133+
self.calibration_invokes.append({
134+
"name": name,
135+
"parameters": parameters,
136+
"instructions": instructions
137+
})
138+
129139

130140
def to_tqasm(self) -> str:
131141
qasm_lines = []
@@ -149,6 +159,10 @@ def to_tqasm(self) -> str:
149159
qasm_lines.append(f" play({inst['frame']}, {wf_type}({args_str}));")
150160
qasm_lines.append("}")
151161

162+
for cal in getattr(self, "calibration_invokes", []):
163+
pname = ", ".join(cal["parameters"])
164+
qasm_lines.append(f"\n {cal['name']} {pname};")
165+
152166
return "\n".join(qasm_lines)
153167

154168
def calibrate(self, name: str, parameters: List["Param"]) -> "DefcalBuilder":
@@ -1078,8 +1092,8 @@ def play(self, frame_name: str, waveform: Any, start_time: int = None):
10781092
return self
10791093

10801094
def build(self):
1081-
self.circuit.add_calibration(
1095+
self.circuit.def_calibration(
10821096
name=self.name,
10831097
parameters=[p.name for p in self.parameters],
10841098
instructions=self.instructions,
1085-
)
1099+
)

0 commit comments

Comments
 (0)