Skip to content

Commit efb4b61

Browse files
committed
Improve configurability of QASMParser
1 parent 6b65e1f commit efb4b61

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

quantumsim/qasm.py

+14-8
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,19 @@ def dropnil(lst):
4646

4747
class QASMParser(parsimonious.NodeVisitor):
4848

49-
def __init__(self, dt=(20, 40), t1=30000, t2=30000):
49+
def __init__(self, qubit_parameters, dt=(20, 40)):
50+
5051
self.grammar = qasm_grammar
5152
self.lines = []
5253
self.qubit_names = []
5354

54-
self.t1, self.t2 = t1, t2
55-
5655
self.timestep = 0
57-
5856
self.circuits = []
5957
self.gates = []
58+
self.qubit_parameters = qubit_parameters
6059
self.timestep_increment_sgl = dt[0]
6160
self.timestep_increment_dbl = dt[1]
62-
self.timestep_increment = min(dt[0], dt[1])
61+
self.timestep_increment = min(self.timestep_increment_dbl, self.timestep_increment_sgl)
6362

6463
def visit_qubit_spec(self, node, children):
6564
self.qubit_names.append(children[1])
@@ -68,7 +67,9 @@ def visit_initall(self, node, children):
6867
self.timestep = 0
6968
self.current_circuit = ct.Circuit("Circuit # " + str(len(self.circuits)))
7069
for qb in self.qubit_names:
71-
self.current_circuit.add_qubit(qb, t1=self.t1, t2=self.t2)
70+
t1 = self.qubit_parameters[qb]['T1']
71+
t2 = self.qubit_parameters[qb]['T2']
72+
self.current_circuit.add_qubit(qb, t1=t1, t2=t2)
7273

7374
def visit_gatelist(self, node, children):
7475
self.timestep += self.timestep_increment
@@ -104,11 +105,16 @@ def visit_id(self, node, children):
104105
return node.text
105106

106107
def visit_meas(self, node, children):
107-
self.current_circuit.add_waiting_gates(tmin=0, tmax=self.timestep+self.timestep_increment_sgl)
108+
for b in self.qubit_names:
109+
p_exc = self.qubit_parameters[b]['frac1_0']
110+
p_dec = 1-self.qubit_parameters[b]['frac1_1']
111+
ro_gate = ct.ButterflyGate(b, p_exc=p_exc, p_dec=p_dec,
112+
time=self.timestep)
113+
self.current_circuit.add_gate(ro_gate)
114+
self.current_circuit.add_waiting_gates(tmin=0, tmax=self.timestep)
108115
self.current_circuit.order()
109116

110117
self.circuits.append(self.current_circuit)
111118

112119
def generic_visit(self, node, children):
113120
pass
114-

0 commit comments

Comments
 (0)