The class file for quantum machines.
One can implement an AAIS in a QMachine. Signal lines
and instructions are supported inside it.
A quantum machine is essentially a container of signal
lines, instructions and (local or global) variables.
A signal line contains multiple instructions. Instructions
sharing a signal line cannot be called simultaneously.
Global variables are defined for the QMachine as a
globally tunable parameter. They will be fixed for the
whole experiment.
An instruction may contain several local variables. Local
variables can be tuned for each call of the instruction.
Both variables can be used in the description of its
Hamiltonian.
TODO: Add API for variables' bounds.
GlobalVar
Bases: BaseVar
A global variable, belonging to a QMachine.
One can set its initial value, lower and upper bounds
when declaring it.
Source code in SimuQ/simuq/qmachine.py
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124 | class GlobalVar(BaseVar) :
""" A global variable, belonging to a QMachine.
One can set its initial value, lower and upper bounds
when declaring it.
"""
def __init__(self, mach, init_value = 0, lower_bound = -np.inf, upper_bound = np.inf) :
super().__init__(mach)
self.index = mach.num_gvars
mach.num_gvars += 1
mach.gvars.append(self)
self.init_value = init_value
self.lower_bound = lower_bound
self.upper_bound = upper_bound
def to_exp(self) :
e = Expression.id_gvar(self.mach, self.index)
return e
|
Instruction
An instruction.
It contains the local variables belonging to it, its
property, and its instruction Hamiltonian.
Source code in SimuQ/simuq/qmachine.py
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104 | class Instruction :
""" An instruction.
It contains the local variables belonging to it, its
property, and its instruction Hamiltonian.
"""
def __init__(self, line, prop, name = 'ins') :
self.mach = line.mach
self.line = line
line.inss.append(self)
self.index = self.mach.num_inss
self.mach.num_inss += 1
self.vars_index = []
self.prop = prop
self.name = name
self.is_sys_ham = False
def set_ham(self, h) :
newh = copy(h)
for i in range(len(h.ham)) :
if not isinstance(h.ham[i][1], Expression) :
newh.ham[i] = (h.ham[i][0], h.ham[i][1] * Expression.unit(self.mach))
self.h = newh
def exp_eval(self, gvars, lvars) :
return self.h.exp_eval(gvars, lvars)
|
LocalVar
Bases: BaseVar
A local vabiable, belonging to an instruction.
One can set its initial value, lower and upper bounds
when declaring it.
Source code in SimuQ/simuq/qmachine.py
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146 | class LocalVar(BaseVar) :
""" A local vabiable, belonging to an instruction.
One can set its initial value, lower and upper bounds
when declaring it.
"""
def __init__(self, ins, init_value = 0, lower_bound = -np.inf, upper_bound = np.inf) :
mach = ins.mach
super().__init__(mach)
self.index = mach.num_lvars
ins.vars_index.append(self.index)
mach.num_lvars += 1
mach.lvars.append(self)
self.init_value = init_value
self.lower_bound = lower_bound
self.upper_bound = upper_bound
def to_exp(self) :
e = Expression.id_lvar(self.mach, self.index)
return e
|
QMachine
Bases: BaseQuantumEnvironment
A quantum device described by its AAIS.
It stores the signal lines, instructions, local
variables and global variables.
Source code in SimuQ/simuq/qmachine.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63 | class QMachine(BaseQuantumEnvironment) :
""" A quantum device described by its AAIS.
It stores the signal lines, instructions, local
variables and global variables.
"""
def __init__(self) :
super().__init__()
self.num_gvars = 0
self.gvars = []
self.num_lvars = 0
self.lvars = []
self.num_lines = 0
self.lines = []
self.num_inss = 0
self.sys_ham = 0
self.with_sys_ham = False
self.instantiated = False
def set_sys_ham(self, h) :
self.sys_ham = h
self.with_sys_ham = True
def instantiate_sys_ham(self) :
if self.with_sys_ham and not self.instantiated :
SysLine = SignalLine(self)
SysIns = Instruction(SysLine, 'native', 'System Hamiltonian')
SysIns.set_ham(self.sys_ham)
SysIns.is_sys_ham = True
self.instantiated = True
def extend_instruction_sites(self) :
for line in self.lines :
for ins in line.inss :
ins.h.extend_sites(self.sites_type)
|
SignalLine
A signal line.
It contains all instructions belonging to it.
Source code in SimuQ/simuq/qmachine.py
66
67
68
69
70
71
72
73
74
75
76 | class SignalLine :
""" A signal line.
It contains all instructions belonging to it.
"""
def __init__(self, mach) :
self.mach = mach
self.index = mach.num_lines
mach.num_lines += 1
mach.lines.append(self)
self.inss = []
|