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,115 @@
|
|
|
1
|
+
"""Decoupling stages for choose_S1: which couplings the solver tries to zero, in sequence.
|
|
2
|
+
|
|
3
|
+
A Stage names the matrices whose couplings become solver terms, each term keyed
|
|
4
|
+
(name, i, j). Square matrices contribute their upper off-diagonal entries;
|
|
5
|
+
rectangular matrices, one column per retained mode, contribute their entries in
|
|
6
|
+
noncompact columns. Built-in names:
|
|
7
|
+
|
|
8
|
+
- "J": junction matrix omega_J diag(E_J) omega_J^T, one placeholder E_J per junction
|
|
9
|
+
- "L": inductive matrix L~*
|
|
10
|
+
- "Cinv": charging matrix C~^{-1}
|
|
11
|
+
- "wJ" (rows): junction incidence omega_J~^T, one row per junction
|
|
12
|
+
|
|
13
|
+
A custom entry is (name, matrix) or (name, matrix, law), with the matrix in
|
|
14
|
+
coords.types column order. A square matrix transforms by congruence S^T A S
|
|
15
|
+
(law "flux", the default, like L~*) or contragrediently S^{-1} G S^{-T} (law
|
|
16
|
+
"charge", like C~^{-1}); a rectangular one as M S, like omega_J~^T.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from dataclasses import dataclass
|
|
20
|
+
from typing import NamedTuple
|
|
21
|
+
|
|
22
|
+
import sympy as sym
|
|
23
|
+
|
|
24
|
+
from .patterns import most_zeros_first
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@dataclass(frozen=True)
|
|
28
|
+
class Stage:
|
|
29
|
+
"""One decoupling stage: square and rectangular matrices, and the search order over their terms."""
|
|
30
|
+
|
|
31
|
+
square: tuple = ()
|
|
32
|
+
rows: tuple = ()
|
|
33
|
+
order: object = most_zeros_first
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
# sircuitenum's choose_Z: junction couplings first, then inductive and charging couplings.
|
|
37
|
+
SIRCUITENUM = (Stage(square=("J",)), Stage(square=("L", "Cinv")))
|
|
38
|
+
|
|
39
|
+
# (old type, new type) blocks of S_1 the first stage opens as free entries, after the seed.
|
|
40
|
+
# sircuitenum's trans_blocks: compact into extended, extended and harmonic into extended,
|
|
41
|
+
# harmonic into harmonic. Compact into compact belongs to the seed, which keeps it integer.
|
|
42
|
+
SIRCUITENUM_BLOCKS = frozenset({("c", "e"), ("e", "e"), ("h", "e"), ("h", "h")})
|
|
43
|
+
ALLOWED_BLOCKS = frozenset({("c", "e"), ("c", "h"), ("e", "e"), ("e", "h"), ("h", "e"), ("h", "h")})
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def trans_blocks(blocks):
|
|
47
|
+
"""sircuitenum's 3x3 trans_blocks, rows and columns (compact, extended, harmonic)."""
|
|
48
|
+
blocks = frozenset(blocks)
|
|
49
|
+
if blocks - ALLOWED_BLOCKS:
|
|
50
|
+
raise ValueError(f"blocks {sorted(blocks - ALLOWED_BLOCKS)} are not free S_1 blocks; "
|
|
51
|
+
f"allowed: {sorted(ALLOWED_BLOCKS)} (compact into compact belongs to the seed)")
|
|
52
|
+
order = ("c", "e", "h")
|
|
53
|
+
return [[int((old, new) in blocks) for new in order] for old in order]
|
|
54
|
+
|
|
55
|
+
LAWS = ("flux", "charge")
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class Target(NamedTuple):
|
|
59
|
+
"""A resolved stage matrix in (compact, extended, harmonic) order."""
|
|
60
|
+
|
|
61
|
+
name: str
|
|
62
|
+
matrix: sym.Matrix # square: in its own law; rows: one column per mode
|
|
63
|
+
law: str # "flux", "charge", or "rows"
|
|
64
|
+
solver: sym.Matrix # what secondary_decouple transforms by congruence (rows: as M Z)
|
|
65
|
+
invert: bool # secondary_decouple inverts the congruence (charge law)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def resolve(stage, builtins, P):
|
|
69
|
+
"""The stage's Targets; builtins maps names to Targets, P reorders coords columns."""
|
|
70
|
+
for entry in stage.square + stage.rows:
|
|
71
|
+
if isinstance(entry, str) and entry not in builtins:
|
|
72
|
+
raise ValueError(f"Unknown stage matrix {entry!r}; built-ins are {sorted(builtins)}")
|
|
73
|
+
square, rows = [], []
|
|
74
|
+
for entry in stage.square:
|
|
75
|
+
if isinstance(entry, str):
|
|
76
|
+
target = builtins[entry]
|
|
77
|
+
if target is not None:
|
|
78
|
+
square.append(target)
|
|
79
|
+
continue
|
|
80
|
+
name, matrix, law = (*entry, "flux") if len(entry) == 2 else entry
|
|
81
|
+
if law not in LAWS:
|
|
82
|
+
raise ValueError(f"Stage matrix {name!r}: law must be 'flux' or 'charge', not {law!r}")
|
|
83
|
+
A = sym.Matrix(matrix)
|
|
84
|
+
if A.shape != (P.rows, P.rows) or A != A.T:
|
|
85
|
+
raise ValueError(f"Stage matrix {name!r} must be symmetric with one row and column per retained mode")
|
|
86
|
+
A = P.T * A * P
|
|
87
|
+
square.append(Target(name, A, law, A if law == "flux" else A.inv(), law == "charge"))
|
|
88
|
+
for entry in stage.rows:
|
|
89
|
+
if isinstance(entry, str):
|
|
90
|
+
target = builtins[entry]
|
|
91
|
+
if target is not None:
|
|
92
|
+
rows.append(target)
|
|
93
|
+
continue
|
|
94
|
+
name, matrix = entry
|
|
95
|
+
M = sym.Matrix(matrix)
|
|
96
|
+
if M.cols != P.rows:
|
|
97
|
+
raise ValueError(f"Stage matrix {name!r} needs one column per retained mode")
|
|
98
|
+
M = M * P
|
|
99
|
+
rows.append(Target(name, M, "rows", M, False))
|
|
100
|
+
return square, rows
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def zero_keys(targets, S, compact):
|
|
104
|
+
"""Keys (name, i, j) of the targets' entries that vanish after S, as in the solver terms."""
|
|
105
|
+
S = sym.Matrix(S)
|
|
106
|
+
zeros = set()
|
|
107
|
+
for t in targets:
|
|
108
|
+
if t.law == "rows":
|
|
109
|
+
T = t.matrix * S
|
|
110
|
+
entries = [(k, j) for k in range(T.rows) for j in range(T.cols) if j not in compact]
|
|
111
|
+
else:
|
|
112
|
+
T = S.T * t.matrix * S if t.law == "flux" else S.inv() * t.matrix * S.inv().T
|
|
113
|
+
entries = [(i, j) for i in range(T.rows) for j in range(i + 1, T.cols)]
|
|
114
|
+
zeros.update((t.name, i, j) for i, j in entries if sym.cancel(T[i, j]) == 0)
|
|
115
|
+
return frozenset(zeros)
|