explore more of 40: multi-wrapped cores

This commit is contained in:
2022-09-24 03:25:32 -07:00
parent c7ac19dcc9
commit ebbaf4c697
3 changed files with 494 additions and 87 deletions

View File

@@ -17,6 +17,8 @@ class Line:
def get(self, x: float) -> float:
from_x, from_y = self.from_
to_x, to_y = self.to
if x == from_x:
return from_y
tween = (x - from_x) / (to_x - from_x)
return tween * to_y + (1-tween) * from_y
@@ -41,11 +43,29 @@ class Piecewise:
(x, 1-y) for (x, y) in self.xy
])
def logically_inverted_x(self) -> 'Piecewise':
return Piecewise([
(1-x, y) for (x, y) in self.xy
][::-1])
def logically_inverted_xy(self) -> 'Piecewise':
return self.logically_inverted_x().logically_inverted()
def shifted_x(self, shift: float) -> 'Piecewise':
return Piecewise([
(x + shift, y) for (x, y) in self.xy
])
def shifted_y(self, shift: float) -> 'Piecewise':
return Piecewise([
(x, y + shift) for (x, y) in self.xy
])
def line_for(self, x: float) -> Line:
for first_lower in self.xy[:-1][::-1]:
if first_lower[0] < x: break
for first_upper in self.xy[1:]:
if first_upper[0] > x: break
if not first_upper[0] < x: break
return Line(first_lower, first_upper)
@@ -59,11 +79,17 @@ class Piecewise:
def get_slope(self, x: float) -> float:
return self.line_for(x).slope()
def get_repeated(self, x: float, n: int = 63) -> float:
def get_repeated(self, x: float, n: int = 255) -> float:
for _ in range(n):
x = self.get(x)
return x
def get_mean(self, x: float, n: int = 100) -> float:
return 1/n * sum(self.get(x * i/(n-1)) for i in range(n))
def get_integral(self, x: float, n: int = 100) -> float:
return self.get_mean(x) * x
def df_for(self, from_: float, to: float, points: int, f) -> DataFrame:
x_step = (to - from_) / (points - 1)
x = [from_ + x_step*x for x in range(points)]
@@ -90,6 +116,98 @@ class Piecewise:
def plot_equilibrium(self, from_: float = 0.0, to: float = 1.0, title: str = "Piecewise"):
self.plot_for(from_, to, title, self.get_repeated)
def plot_integral(self, from_: float = 0.0, to: float = 1.0, title: str = "Piecewise"):
self.plot_for(from_, to, title, self.get_integral)
# stable inverter (ideal)
fwd_fake_step = Piecewise(
[
[ 0.0, 0.0 ],
[ 0.4, 0.0 ],
[ 0.6, 1.0 ],
[ 1.0, 1.0 ],
]
)
# stable inverter (amplifying)
fwd_fake_1_5x = Piecewise(
[
[ 0.0, 0.0 ],
[ 0.65, 1.0 ],
[ 1.0, 1.0 ],
]
)
# stable inverter (amplifying only from 0.3 -> 0.5)
fwd_fake_slope_change_before_0_5 = Piecewise(
[
[ 0.0, 0.2 ],
[ 0.3, 0.3 ],
[ 0.5, 0.6 ],
[ 1.0, 1.0 ],
]
)
# failed inverter (>1.0 slope happens too late)
# flipping x doesn't fix.
# however, shifting x by -0.1 and y by -0.2 and *then* inverting x does.
# - this gives us a concave-up 1-x like curve
fwd_fake_slope_change_after_0_5 = Piecewise(
[
[ 0.0, 0.2 ],
[ 0.3, 0.3 ],
[ 0.6, 0.5 ],
[ 1.0, 1.0 ],
]
)
slope_fake_hill = [
0.8, 0.9, 1.0, 1.1, 1.2, 1.2, 1.1, 1.0, 0.9, 0.8
]
fwd_fake_hill = Piecewise(
[ (0.1*i, 0.1 * sum(slope_fake_hill[0:i])) for i in range(11) ]
)
fwd_fake_asymmetric_hill = Piecewise(
[
(0.0, 0.20),
(0.2, 0.30),
(0.4, 0.45),
(0.6, 0.75),
(0.8, 0.80),
(1.0, 0.85),
]
)
# valid inverter; the [0.6, 1.0] -> 0.8 mapping *fixes* the logic low value to
# 1.0 - 0.8 = 0.2
# and allows anything 0.6 to 1.0 to be recognized as logic high immediately.
# i.e. "bottoming out" is a *good* thing
fwd_fake_asymmetric_flats = Piecewise(
[
(0.0, 0.20),
(0.2, 0.30),
(0.6, 0.80),
(1.0, 0.80),
]
)
fwd_fake_asymmetric_overdrive = Piecewise(
[
(0.0, 0.40),
(0.3, 0.50),
(0.6, 0.85),
(1.0, 0.90),
]
)
fwd_fake_asymmetric_bottom_out = Piecewise(
[
(0.0, 0.00),
(0.8, 0.99),
(1.0, 1.00),
]
)
fwd_17_4_0_8e10 = Piecewise(
[
[ -16381, 6688 ],
@@ -148,12 +266,26 @@ fwd_24_5_1_2e10 = Piecewise(
fwd_24_5_1_5e10 = Piecewise(
[
[ -15208, -6303 ], # -1.00
[ -11991, -4499 ], # -0.30
[ -4757, 531 ], # -0.20
[ 5994, 11126 ], # 0.00
[ 8238, 13048 ], # +0.20
[ 12048, 15346 ], # +1.00
[ -15208, -6303 ],
[ -13396, -5388 ],
[ -11992, -4516 ],
[ -11991, -4499 ],
[ -9379, -2953 ],
[ -4757, 531 ],
[ -2, 4734 ],
[ 3074, 7760 ],
[ 4854, 9784 ],
[ 5611, 10736 ],
[ 5994, 11126 ],
[ 6298, 11404 ],
[ 6678, 11757 ],
[ 7196, 12200 ],
[ 7667, 12589 ],
[ 8238, 13048 ],
[ 8239, 13046 ],
[ 9613, 14027 ],
[ 10585, 14622 ],
[ 12048, 15346 ],
]
).normalized(17000)
@@ -451,12 +583,190 @@ inv_39_2_0_15e10 = Piecewise(
]
).normalized(17000)
fwd_40_12_3_1_5e10 = Piecewise(
[
[ -15617, -4900 ],
[ -15086, -4405 ],
[ -14357, -3941 ],
[ -13828, -3800 ],
[ -13111, -3294 ],
[ -12203, -2582 ],
[ -9321, -169 ],
[ -4645, 4342 ],
[ 422, 9543 ],
[ 5472, 14584 ],
[ 8233, 16078 ],
[ 9249, 16224 ],
[ 9700, 16263 ],
[ 10044, 16286 ],
[ 10643, 16323 ],
[ 11168, 16348 ],
[ 11605, 16367 ],
[ 12054, 16387 ],
[ 12411, 16402 ],
]
).normalized(17000)
fwd_40_6_3_1_5e10 = Piecewise(
[
[ -16046, -5674 ],
[ -15523, -5367 ],
[ -14807, -4923 ],
[ -14350, -4632 ],
[ -13668, -4326 ],
[ -12591, -3719 ],
[ -9752, -1873 ],
[ -5310, 1484 ],
[ -1048, 4991 ],
[ 2517, 7918 ],
[ 5284, 10134 ],
[ 7297, 11623 ],
[ 8629, 12439 ],
[ 9611, 12955 ],
[ 11360, 13845 ],
[ 12188, 14174 ],
[ 12831, 14537 ],
[ 13573, 14838 ],
[ 14082, 14999 ],
]
).normalized(17000)
fwd_40_6_7_1_5e10 = Piecewise(
[
[ -14687, -7326 ],
[ -14108, -7030 ],
[ -13435, -6690 ],
[ -13049, -6503 ],
[ -12522, -6223 ],
[ -11785, -5833 ],
[ -9190, -4410 ],
[ -4649, -1447 ],
[ 250, 2263 ],
[ 3132, 4799 ],
[ 4306, 6177 ],
[ 4961, 7059 ],
[ 5320, 7400 ],
[ 5631, 7670 ],
[ 6516, 8370 ],
[ 8605, 9674 ],
[ 9764, 10342 ],
[ 10753, 10874 ],
[ 11283, 11147 ],
]
).normalized(15000)
fwd_40_600um_20_3_1_5e10 = Piecewise(
[
[ -9878, -1348 ],
[ -9392, -985 ],
[ -8694, -508 ],
[ -8256, -360 ],
[ -7609, -221 ],
[ -4128, 1930 ],
[ -974, 4269 ],
[ 2142, 6978 ],
[ 3895, 8940 ],
[ 5049, 10512 ],
[ 5838, 11677 ],
[ 6192, 11925 ],
[ 6415, 12017 ],
[ 6613, 12086 ],
[ 6960, 12202 ],
[ 7282, 12311 ],
[ 7658, 12407 ],
[ 8037, 12562 ],
[ 8272, 12695 ],
]
).normalized(19000)
fwd_40_600um_20_3_1_1e11 = Piecewise(
[
[ -12167, -1233 ],
[ -11552, -655 ],
[ -10820, -93 ],
[ -10370, 199 ],
[ -9825, 434 ],
[ -9043, 844 ],
[ -8573, 1101 ],
[ -7905, 1565 ],
[ -4197, 4541 ],
[ 1886, 9344 ],
[ 5011, 11888 ],
[ 6604, 12899 ],
[ 7932, 13602 ],
[ 8423, 13730 ],
[ 8645, 13888 ],
[ 8942, 13962 ],
[ 9318, 14166 ],
[ 9554, 14252 ],
]
).normalized(15000)
fwd_40_600um_12_5_1_1e11 = Piecewise(
[
[ -11814, -3658 ],
[ -11192, -3265 ],
[ -10456, -2801 ],
[ -10025, -2587 ],
[ -9522, -2256 ],
[ -8805, -1836 ],
[ -8362, -1556 ],
[ -7702, -1105 ],
[ 315, 4617 ],
[ 4359, 9016 ],
[ 5981, 10366 ],
[ 6782, 10836 ],
[ 7084, 11037 ],
[ 7501, 11328 ],
[ 8045, 11716 ],
[ 8395, 12070 ],
]
).normalized(13000)
fwd_40_600um_6_11_1_5e10 = Piecewise(
[
[ -9209, -10033 ],
[ -8755, -9809 ],
[ -8113, -9520 ],
[ -7741, -9312 ],
[ -7180, -9051 ],
[ -4152, -8422 ],
[ -1328, -7790 ],
[ 117, -7317 ],
[ 1037, -6894 ],
[ 1580, -6541 ],
[ 1870, -6257 ],
[ 2055, -6046 ],
[ 2191, -5921 ],
[ 2366, -5783 ],
[ 3097, -5430 ],
[ 4014, -5084 ],
[ 4496, -4826 ],
[ 4942, -4641 ],
[ 5175, -4562 ],
]
).normalized(11000)
for (name, curve) in [
# ("fake step", fwd_fake_step.logically_inverted()),
# ("fake 1.5x", fwd_fake_1_5x.logically_inverted()),
# ("fake slope-change", fwd_fake_slope_change_before_0_5.logically_inverted()),
# ("fake slope-change (delayed)", fwd_fake_slope_change_after_0_5.logically_inverted()),
# ("fake slope-change (delayed, shifted)", fwd_fake_slope_change_after_0_5.shifted_x(-0.1).logically_inverted()),
# ("fake slope-change (delayed, shifted, inv-xy)", fwd_fake_slope_change_after_0_5.shifted_x(-0.1).shifted_y(-0.2).logically_inverted_x()),
# ("fake slope-change (delayed, flipped)", fwd_fake_slope_change_after_0_5.logically_inverted_x().logically_inverted()),
# ("fake hill", fwd_fake_hill.logically_inverted()),
# ("fake asymmetric hill", fwd_fake_asymmetric_hill.logically_inverted()),
("fake asymmetric flats", fwd_fake_asymmetric_flats.logically_inverted()),
("fake asymmetric overdrive", fwd_fake_asymmetric_overdrive.logically_inverted()),
("fake asymmetric bottom out", fwd_fake_asymmetric_bottom_out.logically_inverted()),
# ("18", fwd_18.logically_inverted()),
("24 5:1 (2e10 I)", fwd_24_5_1_2e10.logically_inverted()),
("24 5:1 (5e10 I)", fwd_24_5_1_5e10.logically_inverted()),
("24 5:1 (8e10 I)", fwd_24_5_1_8e10.logically_inverted()),
("26", fwd_26.logically_inverted()),
# ("24 5:1 (2e10 I)", fwd_24_5_1_2e10.logically_inverted()),
# ("24 5:1 (5e10 I)", fwd_24_5_1_5e10.logically_inverted()),
# ("24 5:1 (8e10 I)", fwd_24_5_1_8e10.logically_inverted()),
# ("26", fwd_26.logically_inverted()),
# ("38 1:0 (2e10 I)", fwd_38_1_0.logically_inverted()),
# ("38 1:0 (5e10 I)", fwd_38_1_0_5e10.logically_inverted()),
# ("38 2:0 (2e10 I)", fwd_38_2_0.logically_inverted()),
@@ -470,7 +780,19 @@ for (name, curve) in [
# ("39 2:0 (8e10 I)", inv_39_2_0_8e10),
# ("39 2:0 (1e11 I)", inv_39_2_0_1e11),
# ("39 2:0 (15e10 I)", inv_39_2_0_15e10),
# ("40 12x 3:1 (400um, 5e10 I)", fwd_40_12_3_1_5e10.logically_inverted()),
# ("40 6x 3:1 (400um, 5e10 I)", fwd_40_6_3_1_5e10.logically_inverted()),
# ("40 6x 7:1 (400um, 5e10 I)", fwd_40_6_7_1_5e10.logically_inverted()),
# ("40 20x 3:1 (600um, 5e10 I)", fwd_40_600um_20_3_1_5e10.logically_inverted()),
# ("40 20x 3:1 (600um, 5e10 I)-flipped-xy", fwd_40_600um_20_3_1_5e10.logically_inverted_x()),
# # ("40 20x 3:1 (600um, 5e10 I)-flipped", fwd_40_600um_20_3_1_5e10.logically_inverted_x()),
# # ("40 20x 3:1 (600um, 5e10 I)-shifted", fwd_40_600um_20_3_1_5e10.shifted_x(-0.10).logically_inverted()),
# ("40 20x 3:1 (600um, 1e11 I)", fwd_40_600um_20_3_1_1e11.logically_inverted()),
# ("40 12x 5:1 (600um, 1e11 I)", fwd_40_600um_12_5_1_1e11.logically_inverted()),
# ("40 6x 11:1 (600um, 5e10 I)", fwd_40_600um_6_11_1_5e10.logically_inverted()),
]:
curve.plot(title = f"{name} mapping")
curve.logically_inverted().plot_slope(title = f"{name} slope")
curve.plot_equilibrium(title = f"{name} equilibrium")
# curve.plot_integral(title = f"{name} integrated")

View File

@@ -21,16 +21,16 @@ def extract_one(path: str, t_first: float, t_last: float):
def extract_39xx(base_path: str, t_first: str = "2e-9", t_last: str = "3e-9"):
base_dir, prefix = os.path.split(base_path)
mappings = []
mappings = {}
for entry in os.listdir(base_dir):
if entry.startswith(prefix):
(input_, output) = extract_one(os.path.join(base_dir, entry, "meas.csv"), float(t_first), float(t_last))
mappings.append((input_, output))
mappings[int(round(input_))] = int(round(output))
print("Piecewise(")
print(" [")
for i, o in sorted(mappings):
print(f" [ {int(round(i)):6}, {int(round(o)):6} ],")
for i, o in sorted(mappings.items()):
print(f" [ {i:6}, {o:6} ],")
print(" ]")
print(")")