Skip to content

Commit

Permalink
Quick fix copying symbolic Hamiltonian
Browse files Browse the repository at this point in the history
  • Loading branch information
sambonkov committed Jun 14, 2024
1 parent 793525f commit 3760234
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
27 changes: 12 additions & 15 deletions SQcircuit/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,8 @@ def safecopy(self, save_eigs=False):
new_circuit._efreqs = sqf.array([])
new_circuit._evecs = []

new_circuit.descrip_vars = None # TODO -- long-term change

# Deepcopy the whole thing
return deepcopy(new_circuit)

Expand Down Expand Up @@ -946,17 +948,17 @@ def compute_params(self):
self.descrip_vars['charge_dim'] = np.sum(self.omega == 0)
self.descrip_vars['omega'] = self.omega \
/ (2 * np.pi * unt.get_unit_freq())

self.descrip_vars['phi_zp'] = (2 * np.pi / unt.Phi0) \
* np.sqrt(unt.hbar / (2 * np.sqrt(np.diag(self.lTrans)[:harDim]
* np.sqrt(unt.hbar / (2 * np.sqrt(np.diag(self.lTrans)[:harDim]
/ np.diag(self.cInvTrans)[:harDim])))
self.descrip_vars['ng'] = [self.charge_islands[i].value() \
for i in range(harDim, self.n)]
self.descrip_vars['EC'] = ((2 * unt.e) ** 2 / (unt.hbar * 2 * np.pi \
* unt.get_unit_freq())) \
* np.diag(np.repeat(0.5, self.n)) \
* self.cInvTrans

self.descrip_vars['W'] = np.round(self.wTrans, 6)
self.descrip_vars['S'] = np.round(self.S, 3)
if self.loops:
Expand All @@ -965,19 +967,14 @@ def compute_params(self):
self.descrip_vars['B'] = np.zeros((len(self.elem_keys[Junction])
+ len(self.elem_keys[Inductor]), 1))

## values of elements
def elem_value(val):
if get_optim_mode(): return val.item()
else: return val

self.descrip_vars['EJ'] = []
self.descrip_vars['EJ'] = []
for _, el, _, _ in self.elem_keys[Junction]:
self.descrip_vars['EJ'].append(elem_value(el.get_value()) / \
self.descrip_vars['EJ'].append(sqf.numpy(el.get_value()) / \
(2 * np.pi * unt.get_unit_freq()))
self.descrip_vars['EL'] = []
self.descrip_vars['EL'] = []
self.descrip_vars['EL_incl'] = []
for _, el, B_idx in self.elem_keys[Inductor]:
self.descrip_vars['EL'].append(elem_value(el.get_value(unt._unit_ind)))
self.descrip_vars['EL'].append(sqf.numpy(el.get_value(unt._unit_ind)))
self.descrip_vars['EL_incl'].append(
np.sum(np.abs(self.descrip_vars['B'][B_idx, :])) != 0)

Expand All @@ -988,12 +985,12 @@ def elem_value(val):
unt.hbar * 2 * np.pi * unt.get_unit_freq()) * \
self.cInvTrans[i, j]
if i == j:
self.descrip_vars['EC'][(i,j)] /= 2
self.descrip_vars['EC'][(i,j)] /= 2

## values of loops
self.descrip_vars['n_loops'] = len(self.loops)
self.descrip_vars['loops'] = [self.loops[i].value() / 2 / np.pi \
for i in range(len(self.loops))]
self.descrip_vars['loops'] = [sqf.numpy(self.loops[i].value()) / 2 / np.pi \
for i in range(len(self.loops))]

def description(
self,
Expand Down
10 changes: 5 additions & 5 deletions SQcircuit/symbolic.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __new__(cls, plainname, latexname):

def _latex(self, printer):
return printer.doprint(self.lsymbol)


class qOperator(Operator):
"""
Expand All @@ -36,7 +36,7 @@ def __new__(cls, name, subscript=None):
self.opname = name
self.sub = subscript
return self

def _latex(self, printer):
if self.opname[-1] == 'd':
tex = fr'\hat{{{self.opname[:-1]}}}^\dagger'
Expand All @@ -51,7 +51,7 @@ def phi_op(i):
fr'\hat{{\varphi}}_{{{i}}}')

def a(i):
return qOperator('a', i)
return qOperator('a', i)

def ad(i):
return qOperator('ad', i)
Expand Down Expand Up @@ -137,12 +137,12 @@ def jj_hamil(elem_keys, coeff_dict):
sm.nsimplify(B_sym.dot(phi_exts)),
evaluate=False))
return hamil

def construct_hamiltonian(cr):
LC_hamil = sm.Add(har_mode_hamil(cr.descrip_vars),
charge_mode_hamil(cr.descrip_vars), evaluate=False)
Ind_hamil = inductive_hamil(cr.elem_keys, cr.descrip_vars)
JJ_hamil = jj_hamil(cr.elem_keys, cr.descrip_vars)

return sm.Add(*[H for H in [LC_hamil, Ind_hamil, JJ_hamil] if H!=0],
evaluate=False)

0 comments on commit 3760234

Please sign in to comment.