circuit-quantization 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- circuit_quantization/__init__.py +64 -0
- circuit_quantization/circuit.py +258 -0
- circuit_quantization/draw.py +199 -0
- circuit_quantization/flux.py +54 -0
- circuit_quantization/hamiltonian.py +101 -0
- circuit_quantization/io.py +704 -0
- circuit_quantization/lagrangian.py +85 -0
- circuit_quantization/loops.py +248 -0
- circuit_quantization/modes.py +672 -0
- circuit_quantization/numeric_spec.py +199 -0
- circuit_quantization/numerical.py +391 -0
- circuit_quantization/optimize/__init__.py +32 -0
- circuit_quantization/optimize/_utils.py +37 -0
- circuit_quantization/optimize/choose.py +396 -0
- circuit_quantization/optimize/equationset.py +358 -0
- circuit_quantization/optimize/patterns.py +88 -0
- circuit_quantization/optimize/poly_solver.sing +381 -0
- circuit_quantization/optimize/rational_check.py +675 -0
- circuit_quantization/optimize/singular_interface.py +1071 -0
- circuit_quantization/optimize/stages.py +115 -0
- circuit_quantization/optimize/transforms.py +1337 -0
- circuit_quantization/optimize/z3_interface.py +794 -0
- circuit_quantization/qpackage_interface.py +126 -0
- circuit_quantization/quantize.py +186 -0
- circuit_quantization/shear.py +252 -0
- circuit_quantization/units.py +91 -0
- circuit_quantization-0.1.0.dist-info/METADATA +99 -0
- circuit_quantization-0.1.0.dist-info/RECORD +31 -0
- circuit_quantization-0.1.0.dist-info/WHEEL +5 -0
- circuit_quantization-0.1.0.dist-info/licenses/LICENSE +674 -0
- circuit_quantization-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"""Element and incidence matrices of the node Lagrangian."""
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
|
|
5
|
+
import sympy as sym
|
|
6
|
+
|
|
7
|
+
from .circuit import incidence
|
|
8
|
+
|
|
9
|
+
__all__ = ["Lagrangian", "lagrangian"]
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass(frozen=True)
|
|
13
|
+
class Lagrangian:
|
|
14
|
+
"""Incidence, capacitance, inductance, and source matrices of the node Lagrangian.
|
|
15
|
+
|
|
16
|
+
Node rows are ordered int | gnd | src, and a floating circuit has no gnd row.
|
|
17
|
+
Branch columns are ordered C | J | L | V.
|
|
18
|
+
|
|
19
|
+
:ivar Omega: Incidence matrix, +1 at each branch's tail and -1 at its head.
|
|
20
|
+
:ivar Omega_int: Internal-node rows of Omega.
|
|
21
|
+
:ivar C_b: Diagonal matrix of branch capacitances [F].
|
|
22
|
+
:ivar C_int: Internal block of the node capacitance matrix Omega C_b Omega^T.
|
|
23
|
+
:ivar C_int_src: Internal-by-source block of Omega C_b Omega^T, with its sign flipped.
|
|
24
|
+
:ivar Lb_inv: Diagonal matrix of inverse inductances [1/H], inductor branches only.
|
|
25
|
+
:ivar Lstar_int: Internal susceptance L*_int = omega_L_int Lb_inv omega_L_int^T.
|
|
26
|
+
:ivar omega_J_int: Junction columns of Omega_int.
|
|
27
|
+
:ivar omega_L_int: Inductor columns of Omega_int.
|
|
28
|
+
:ivar V: Source-node voltages [V], in circuit.source_nodes order.
|
|
29
|
+
:ivar J: Branch indices of the junctions.
|
|
30
|
+
:ivar L: Branch indices of the inductors.
|
|
31
|
+
:ivar EJ: Josephson energies E_J/h [GHz], in the order of J.
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
Omega: sym.ImmutableMatrix # rows int | gnd | src (no gnd if floating), columns C | J | L | V
|
|
35
|
+
Omega_int: sym.ImmutableMatrix
|
|
36
|
+
C_b: sym.ImmutableMatrix # eq:Cb_diag
|
|
37
|
+
C_int: sym.ImmutableMatrix # eq:C_full_partition
|
|
38
|
+
C_int_src: sym.ImmutableMatrix # eq:C_full_partition, note the sign
|
|
39
|
+
Lb_inv: sym.ImmutableMatrix # L_b^{-1}, inductors only
|
|
40
|
+
Lstar_int: sym.ImmutableMatrix # eq:L_full_partition
|
|
41
|
+
omega_J_int: sym.ImmutableMatrix
|
|
42
|
+
omega_L_int: sym.ImmutableMatrix
|
|
43
|
+
V: sym.ImmutableMatrix # source-node voltages
|
|
44
|
+
J: tuple # branch indices of junctions
|
|
45
|
+
L: tuple # branch indices of inductors
|
|
46
|
+
EJ: tuple
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def lagrangian(circuit):
|
|
50
|
+
"""Element and incidence matrices of a circuit.
|
|
51
|
+
|
|
52
|
+
:param circuit: Circuit with symbolic or numeric element values in SI units.
|
|
53
|
+
:returns: Lagrangian containing incidence, capacitance, inductive, and source matrices.
|
|
54
|
+
"""
|
|
55
|
+
branches = circuit.branches
|
|
56
|
+
n = len(circuit.internal_nodes)
|
|
57
|
+
Omega = incidence(circuit)
|
|
58
|
+
Omega_int = Omega[:n, :]
|
|
59
|
+
J = tuple(k for k, b in enumerate(branches) if b.type == "J")
|
|
60
|
+
L = tuple(k for k, b in enumerate(branches) if b.type == "L")
|
|
61
|
+
|
|
62
|
+
C_b = sym.ImmutableMatrix(sym.diag(*(b.C for b in branches))) # eq:Cb_diag
|
|
63
|
+
C_full = Omega * C_b * Omega.T # eq:C_full_partition
|
|
64
|
+
C_int = C_full[:n, :n]
|
|
65
|
+
# Source rows come last in Omega, after the internal and ground rows.
|
|
66
|
+
C_int_src = -C_full[:n, C_full.cols - len(circuit.source_nodes) :]
|
|
67
|
+
|
|
68
|
+
omega_J_int = Omega_int[:, list(J)]
|
|
69
|
+
omega_L_int = Omega_int[:, list(L)]
|
|
70
|
+
Lb_inv = sym.ImmutableMatrix(sym.diag(*(1 / branches[k].L for k in L)) if L else sym.zeros(0, 0))
|
|
71
|
+
Lstar_int = omega_L_int * Lb_inv * omega_L_int.T # eq:L_full_partition
|
|
72
|
+
|
|
73
|
+
# Each source branch joins ground to its own source node; V follows source-node order.
|
|
74
|
+
voltage = {}
|
|
75
|
+
for b in branches:
|
|
76
|
+
if b.type == "V":
|
|
77
|
+
source_node = b.tail if b.head == circuit.ground else b.head
|
|
78
|
+
voltage[source_node] = b.V
|
|
79
|
+
V = sym.ImmutableMatrix(len(circuit.source_nodes), 1, [voltage[node] for node in circuit.source_nodes])
|
|
80
|
+
|
|
81
|
+
return Lagrangian(
|
|
82
|
+
Omega=Omega, Omega_int=Omega_int, C_b=C_b, C_int=C_int, C_int_src=C_int_src,
|
|
83
|
+
Lb_inv=Lb_inv, Lstar_int=Lstar_int, omega_J_int=omega_J_int, omega_L_int=omega_L_int,
|
|
84
|
+
V=V, J=J, L=L, EJ=tuple(branches[k].EJ for k in J),
|
|
85
|
+
)
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
"""Cycle bases and external fluxes."""
|
|
2
|
+
|
|
3
|
+
from dataclasses import InitVar, dataclass, field
|
|
4
|
+
from itertools import combinations, product
|
|
5
|
+
|
|
6
|
+
import networkx as nx
|
|
7
|
+
import sympy as sym
|
|
8
|
+
|
|
9
|
+
from .circuit import Circuit, _variables, incidence
|
|
10
|
+
|
|
11
|
+
__all__ = ["Loops", "default_tree", "tree_to_G", "branch_dict_to_G", "spanning_trees", "cycle_bases"]
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def spanning_trees(circuit):
|
|
15
|
+
"""Yield each spanning tree as a tuple of branch names in circuit order.
|
|
16
|
+
|
|
17
|
+
Parallel branches count as distinct edges.
|
|
18
|
+
"""
|
|
19
|
+
for tree in nx.SpanningTreeIterator(circuit.graph):
|
|
20
|
+
names = {name for _, _, name in tree.edges(keys=True)}
|
|
21
|
+
yield tuple(name for name in circuit.branch_names if name in names)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def default_tree(circuit):
|
|
25
|
+
"""The minimum spanning tree by branch rank, with J and L before C before V, then circuit order.
|
|
26
|
+
|
|
27
|
+
Growing the J and L subgraph first makes its closure rows span that
|
|
28
|
+
subgraph's cycle space, so superconducting cycles come first in G.
|
|
29
|
+
"""
|
|
30
|
+
return [name for _, _, name in nx.minimum_spanning_edges(circuit.graph, weight="rank", keys=True, data=False)]
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def tree_to_G(circuit, tree):
|
|
34
|
+
"""Closure branches and fundamental cycles G = (G_t I) of a spanning tree.
|
|
35
|
+
|
|
36
|
+
With the root row deleted, G_t = -Omega_c^T (Omega_t^T)^{-1}. The root is the
|
|
37
|
+
ground, or the first node of a floating circuit. Closure branches come in rank
|
|
38
|
+
order, so superconducting cycles come first.
|
|
39
|
+
|
|
40
|
+
:param tree: Branch labels of a spanning tree, e.g. default_tree(circuit).
|
|
41
|
+
:returns: Pair (closure branch names, G) with G columns in circuit.branch_names order.
|
|
42
|
+
"""
|
|
43
|
+
names = circuit.branch_names
|
|
44
|
+
rank = {name: r for _, _, name, r in circuit.graph.edges(keys=True, data="rank")}
|
|
45
|
+
closure = tuple(sorted((name for name in names if name not in tree), key=rank.get))
|
|
46
|
+
root = circuit.nodes.index(circuit.ground) if circuit.ground is not None else 0
|
|
47
|
+
Omega = incidence(circuit)
|
|
48
|
+
Omega = Omega[[i for i in range(Omega.rows) if i != root], :]
|
|
49
|
+
columns = [names.index(name) for name in (*tree, *closure)] # (tree | closure) order
|
|
50
|
+
Omega_t, Omega_c = Omega[:, columns[:len(tree)]], Omega[:, columns[len(tree):]]
|
|
51
|
+
G = sym.Matrix.hstack(-Omega_c.T * Omega_t.T.inv(), sym.eye(len(closure))) # eq:A1
|
|
52
|
+
return closure, sym.ImmutableMatrix(G[:, [columns.index(k) for k in range(len(names))]])
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def branch_dict_to_G(circuit, branch_dict):
|
|
56
|
+
"""Cycle matrix G from {loop name: branch labels}, one row per loop in dict order.
|
|
57
|
+
|
|
58
|
+
A tuple of labels gets its signs from incidence, with the first label +1.
|
|
59
|
+
A signed dict {label: +1 or -1} is used as given.
|
|
60
|
+
|
|
61
|
+
:raises ValueError: Unknown labels, or a tuple that is not a single closed loop.
|
|
62
|
+
"""
|
|
63
|
+
names = circuit.branch_names
|
|
64
|
+
Omega = incidence(circuit)
|
|
65
|
+
rows = []
|
|
66
|
+
for loop, cycle in branch_dict.items():
|
|
67
|
+
if set(cycle) - set(names):
|
|
68
|
+
raise ValueError(f"Cycle {loop!r} uses unknown branches: {sorted(set(cycle) - set(names))}")
|
|
69
|
+
if not isinstance(cycle, dict):
|
|
70
|
+
basis = Omega[:, [names.index(name) for name in cycle]].nullspace()
|
|
71
|
+
if len(cycle) != len(set(cycle)) or len(basis) != 1 or any(x == 0 for x in basis[0]):
|
|
72
|
+
raise ValueError(f"Cycle {loop!r} needs a nonempty tuple of distinct branches forming a single closed loop")
|
|
73
|
+
cycle = dict(zip(cycle, basis[0] / basis[0][0]))
|
|
74
|
+
rows.append([cycle.get(name, 0) for name in names])
|
|
75
|
+
return sym.ImmutableMatrix(len(rows), len(names), [x for row in rows for x in row])
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _closes(circuit, G, closure_branches):
|
|
79
|
+
"""True when G restricted to closure_branches is the identity, as for a tree basis."""
|
|
80
|
+
columns = [circuit.branch_names.index(name) for name in closure_branches]
|
|
81
|
+
return G[:, columns] == sym.eye(G.rows)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def check_loops(circuit, G, names, closure_branches=None, fluxes=()):
|
|
85
|
+
"""Check that G is a cycle basis and that its labels fit.
|
|
86
|
+
|
|
87
|
+
G needs N_ell = N_b - rank(Omega) linearly independent rows with entries
|
|
88
|
+
0, +1, -1 that satisfy G Omega^T = 0. names labels each row.
|
|
89
|
+
closure_branches, if given, are the identity columns of G. fluxes name existing loops.
|
|
90
|
+
"""
|
|
91
|
+
Omega = incidence(circuit)
|
|
92
|
+
N_ell = Omega.cols - Omega.rank()
|
|
93
|
+
if G.shape != (N_ell, Omega.cols) or G.rank() != N_ell:
|
|
94
|
+
raise ValueError(f"G needs N_ell = N_b - rank(Omega) = {N_ell} independent rows of {Omega.cols} entries")
|
|
95
|
+
if any(x not in (-1, 0, 1) for x in G) or any(sym.simplify(G * Omega.T)):
|
|
96
|
+
raise ValueError("G needs entries 0, +1, -1 (a physical loop) and G Omega^T = 0")
|
|
97
|
+
if len(names) != G.rows or len(set(names)) != len(names):
|
|
98
|
+
raise ValueError(f"names needs one name per row of G ({G.rows}), all distinct")
|
|
99
|
+
if set(fluxes) - set(names):
|
|
100
|
+
raise ValueError(f"Fluxes for unknown loops: {sorted(set(fluxes) - set(names))}")
|
|
101
|
+
if closure_branches is not None and not _closes(circuit, G, closure_branches):
|
|
102
|
+
raise ValueError("closure_branches must be the identity columns of G")
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def cycle_bases(circuit, *, primitive=True):
|
|
106
|
+
"""Yield each cycle basis made of simple loops, as a branch_dict for Loops.
|
|
107
|
+
|
|
108
|
+
Rows are named loop_1, loop_2, ... in a canonical order. Each loop is a tuple
|
|
109
|
+
of branch names in circuit order, which Loops orients with its first branch positive.
|
|
110
|
+
primitive=True keeps only bases of the integer cycle lattice, G = T G_tree with det T = +-1.
|
|
111
|
+
False keeps every full-rank basis. The search tries every subset of simple loops,
|
|
112
|
+
so it suits small circuits.
|
|
113
|
+
"""
|
|
114
|
+
graph, names = circuit.graph, circuit.branch_names
|
|
115
|
+
tail = {b.name: b.tail for b in circuit.branches}
|
|
116
|
+
loops = {}
|
|
117
|
+
for nodes in nx.simple_cycles(graph):
|
|
118
|
+
# Expand the node sequence over parallel branches; a two-node loop is a parallel pair.
|
|
119
|
+
keys = [graph[u][v] for u, v in zip(nodes, nodes[1:] + nodes[:1])]
|
|
120
|
+
for hops in combinations(keys[0], 2) if len(nodes) == 2 else product(*keys):
|
|
121
|
+
signs = {name: 1 if tail[name] == u else -1 for u, name in zip(nodes, hops)} # +1 along tail -> head
|
|
122
|
+
loops[tuple(name for name in names if name in signs)] = signs
|
|
123
|
+
# Any basis is G = T G_f, and G_f is the identity on closure columns, so T = G[:, closure].
|
|
124
|
+
tree = default_tree(circuit)
|
|
125
|
+
closure = [name for name in names if name not in tree]
|
|
126
|
+
for basis in combinations(sorted(loops), len(closure)):
|
|
127
|
+
det = sym.Matrix([[loops[loop].get(name, 0) for name in closure] for loop in basis]).det()
|
|
128
|
+
if (abs(det) == 1) if primitive else (det != 0):
|
|
129
|
+
yield {f"loop_{i + 1}": loop for i, loop in enumerate(basis)}
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
@dataclass(frozen=True)
|
|
133
|
+
class Loops:
|
|
134
|
+
"""A complete cycle basis G and the external flux through each cycle.
|
|
135
|
+
|
|
136
|
+
Every cycle not given a value in ``fluxes`` gets a visible symbol Phi_<name> [Wb].
|
|
137
|
+
Pass 0 explicitly for a cycle that encloses no flux. closure_branches is set
|
|
138
|
+
when G comes from a spanning tree. G restricted to them is the identity.
|
|
139
|
+
|
|
140
|
+
:param circuit: Circuit defining the branch labels and orientations.
|
|
141
|
+
:param G: Cycle matrix with one row per loop and columns in circuit.branch_names order.
|
|
142
|
+
:param names: One distinct label per row. None generates loop_1, loop_2, ... .
|
|
143
|
+
:param closure_branches: Tree closure branch for each row, or None.
|
|
144
|
+
:param fluxes: Optional {loop name: flux in Wb}. Missing loops get real Phi_<name> symbols.
|
|
145
|
+
:raises ValueError: G is not a cycle basis of the circuit, or names or fluxes do not fit it.
|
|
146
|
+
"""
|
|
147
|
+
|
|
148
|
+
circuit: Circuit
|
|
149
|
+
G: sym.ImmutableMatrix
|
|
150
|
+
names: tuple = None
|
|
151
|
+
closure_branches: tuple = None
|
|
152
|
+
fluxes: InitVar[dict] = None
|
|
153
|
+
Phi_ext: sym.ImmutableMatrix = field(init=False)
|
|
154
|
+
|
|
155
|
+
def __post_init__(self, fluxes):
|
|
156
|
+
fluxes = dict(fluxes or {})
|
|
157
|
+
G = sym.ImmutableMatrix(self.G)
|
|
158
|
+
names = tuple(self.names) if self.names is not None else tuple(f"loop_{i + 1}" for i in range(G.rows))
|
|
159
|
+
closure = tuple(self.closure_branches) if self.closure_branches is not None else None
|
|
160
|
+
check_loops(self.circuit, G, names, closure, fluxes)
|
|
161
|
+
Phi_ext = [fluxes.get(loop, sym.Symbol(f"Phi_{loop}", real=True)) for loop in names]
|
|
162
|
+
object.__setattr__(self, "G", G)
|
|
163
|
+
object.__setattr__(self, "names", names)
|
|
164
|
+
object.__setattr__(self, "closure_branches", closure)
|
|
165
|
+
object.__setattr__(self, "Phi_ext", sym.ImmutableMatrix(len(names), 1, Phi_ext))
|
|
166
|
+
|
|
167
|
+
@classmethod
|
|
168
|
+
def from_branch_dict(cls, circuit, branch_dict, fluxes=None):
|
|
169
|
+
"""Loops named and ordered as branch_dict, with G from branch_dict_to_G."""
|
|
170
|
+
return cls(circuit, branch_dict_to_G(circuit, branch_dict), tuple(branch_dict), fluxes=fluxes)
|
|
171
|
+
|
|
172
|
+
@classmethod
|
|
173
|
+
def from_tree(cls, circuit, tree, fluxes=None):
|
|
174
|
+
"""Fundamental loops of a spanning tree, each named after its closure branch."""
|
|
175
|
+
closure, G = tree_to_G(circuit, tree)
|
|
176
|
+
return cls(circuit, G, closure, closure, fluxes=fluxes)
|
|
177
|
+
|
|
178
|
+
@classmethod
|
|
179
|
+
def from_circuit(cls, circuit, *, zero_capacitive=False):
|
|
180
|
+
"""Generate and print fundamental cycles from the default spanning tree.
|
|
181
|
+
|
|
182
|
+
The deterministic tree prioritizes J/L over C/V branches in circuit
|
|
183
|
+
order. Each loop is named after its closure branch, whose sign is +1.
|
|
184
|
+
Prints signed branches, classification, and flux, one loop per line.
|
|
185
|
+
For custom cycles or flux values, use :meth:`from_branch_dict` or
|
|
186
|
+
:meth:`from_tree`.
|
|
187
|
+
|
|
188
|
+
:param circuit: Circuit whose fundamental cycles are generated.
|
|
189
|
+
:param bool zero_capacitive: If True, set every loop containing a C or V
|
|
190
|
+
branch to zero flux. Otherwise generate a real Phi_<name> symbol
|
|
191
|
+
for every loop. Junction/inductor capacitance does not count as
|
|
192
|
+
a capacitively broken branch. Default False.
|
|
193
|
+
:returns: Loops with G, names, closure_branches, Phi_ext, and variables.
|
|
194
|
+
"""
|
|
195
|
+
closure, G = tree_to_G(circuit, default_tree(circuit))
|
|
196
|
+
capacitive = [k for k, b in enumerate(circuit.branches) if b.type in ("C", "V")]
|
|
197
|
+
broken = {loop for i, loop in enumerate(closure) if any(G[i, k] for k in capacitive)}
|
|
198
|
+
result = cls(circuit, G, closure, closure, fluxes=dict.fromkeys(broken, 0) if zero_capacitive else {})
|
|
199
|
+
for loop, flux in zip(result.names, result.Phi_ext):
|
|
200
|
+
elements = " ".join(f"{'+' if sign == 1 else '-'}{name}" for name, sign in result.branch_dict[loop].items())
|
|
201
|
+
kind = "capacitively broken" if loop in broken else "superconducting"
|
|
202
|
+
print(f"{loop}: {elements} [{kind}]; flux = {flux}")
|
|
203
|
+
if not closure:
|
|
204
|
+
print("No loops.")
|
|
205
|
+
return result
|
|
206
|
+
|
|
207
|
+
@property
|
|
208
|
+
def branch_dict(self):
|
|
209
|
+
"""{loop name: {branch label: +1 or -1}}, closure branch first when known, then circuit order.
|
|
210
|
+
|
|
211
|
+
Signed, so from_branch_dict(circuit, loops.branch_dict) rebuilds the same G.
|
|
212
|
+
"""
|
|
213
|
+
closure = self.closure_branches or (None,) * len(self.names)
|
|
214
|
+
branch_dict = {}
|
|
215
|
+
for loop, first, row in zip(self.names, closure, self.G.tolist()):
|
|
216
|
+
signs = {first: 1} if first is not None else {} # a closure branch is +1 in its own row
|
|
217
|
+
for name, sign in zip(self.circuit.branch_names, row):
|
|
218
|
+
if sign and name != first:
|
|
219
|
+
signs[name] = sign
|
|
220
|
+
branch_dict[loop] = signs
|
|
221
|
+
return branch_dict
|
|
222
|
+
|
|
223
|
+
@property
|
|
224
|
+
def variables(self):
|
|
225
|
+
"""Unique external-flux symbols in loop order, including explicit expressions."""
|
|
226
|
+
return _variables(self.Phi_ext)
|
|
227
|
+
|
|
228
|
+
def rebase(self, G_new, names=None):
|
|
229
|
+
"""Re-express the same fluxes in another cycle basis G_new = T G.
|
|
230
|
+
|
|
231
|
+
closure_branches carry over only while G_new is still the identity on them.
|
|
232
|
+
|
|
233
|
+
:param G_new: Complete cycle matrix in the same branch-column order as G.
|
|
234
|
+
Must be related to G by an integer unimodular transformation.
|
|
235
|
+
:param names: One unique label per new row. None generates loop_1, loop_2, ... .
|
|
236
|
+
:returns: New Loops with transformed fluxes, preserving their physical meaning.
|
|
237
|
+
:raises ValueError: Invalid basis, non-unimodular transformation, or invalid names.
|
|
238
|
+
"""
|
|
239
|
+
G_new = sym.ImmutableMatrix(G_new)
|
|
240
|
+
names = tuple(names) if names is not None else tuple(f"loop_{i + 1}" for i in range(G_new.rows))
|
|
241
|
+
check_loops(self.circuit, G_new, names) # G_new is a cycle basis, so G_new = T G exactly
|
|
242
|
+
T = G_new * self.G.T * (self.G * self.G.T).inv()
|
|
243
|
+
if any(not x.is_integer for x in T) or abs(T.det()) != 1:
|
|
244
|
+
raise ValueError("G_new = T G needs T integer with det T = +-1")
|
|
245
|
+
closure = self.closure_branches
|
|
246
|
+
if closure is not None and not _closes(self.circuit, G_new, closure):
|
|
247
|
+
closure = None
|
|
248
|
+
return Loops(self.circuit, G_new, names, closure, fluxes=dict(zip(names, T * self.Phi_ext)))
|