From 109d41142f8dc89d692571d5fd1bf20e236b89ee Mon Sep 17 00:00:00 2001 From: Tianpu Zhao Date: Thu, 23 Jun 2022 13:27:24 -0700 Subject: [PATCH] Fixed the Issue #139 on identifying loops in circuits with more than 1 capacitor islands --- scqubits/core/circuit.py | 4 ++-- scqubits/core/symbolic_circuit.py | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/scqubits/core/circuit.py b/scqubits/core/circuit.py index 44f7364d..7a505eb9 100644 --- a/scqubits/core/circuit.py +++ b/scqubits/core/circuit.py @@ -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 ) diff --git a/scqubits/core/symbolic_circuit.py b/scqubits/core/symbolic_circuit.py index 4fcd4c08..888cee83 100644 --- a/scqubits/core/symbolic_circuit.py +++ b/scqubits/core/symbolic_circuit.py @@ -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