Skip to content

Commit

Permalink
Fixed the Issue #139 on identifying loops in circuits with more than …
Browse files Browse the repository at this point in the history
…1 capacitor islands
  • Loading branch information
ZhaoTianPu committed Jun 23, 2022
1 parent 4e9e679 commit 109d411
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions scqubits/core/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1805,14 +1805,14 @@ def sym_hamiltonian(
)
else:
sym_hamiltonian = sm.Add(
sm.UnevaluatedExpr(
(
self._make_expr_human_readable(
self.hamiltonian_symbolic.expand()
- self.potential_symbolic.expand(),
float_round=float_round,
)
),
sm.UnevaluatedExpr(
(
self._make_expr_human_readable(
self.potential_symbolic.expand(), float_round=float_round
)
Expand Down
12 changes: 6 additions & 6 deletions scqubits/core/symbolic_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1463,19 +1463,19 @@ def _find_loop(self, closure_branch: Branch) -> List["Branch"]:
gen_1, ancestors_1, path_1 = self._find_path_to_root(closure_branch.nodes[0])
gen_2, ancestors_2, path_2 = self._find_path_to_root(closure_branch.nodes[1])
# find the first common ancestor of these two nodes
# start from the root node, find out the last generation where two nodes have the
# start from the root node, find out the last sub-generation where two nodes have the
# same ancestor
gen_last_same_ancestor = 0
for igen in range(min(gen_1, gen_2)):
sub_gen_last_same_ancestor = -1
for igen in range(min(len(ancestors_1), len(ancestors_2))):
if ancestors_1[igen].id == ancestors_2[igen].id:
gen_last_same_ancestor = igen
sub_gen_last_same_ancestor = igen
elif ancestors_1[igen].id != ancestors_2[igen].id:
break
# get all the branches of the paths from the two nodes to the root, after the last
# shared ancestor, and the closure branch itself
loop = (
path_1[gen_last_same_ancestor:]
+ path_2[gen_last_same_ancestor:]
path_1[sub_gen_last_same_ancestor+1:]
+ path_2[sub_gen_last_same_ancestor+1:]
+ [closure_branch]
)
return loop
Expand Down

0 comments on commit 109d411

Please sign in to comment.