Compare commits

...

9 Commits

Author SHA1 Message Date
colin af4b5ffa32 app: stacked_cores: 53-xx: complete a 1:1 coupled buffer
slope is poor, hovering around a constant 0.75 transmission ratio.
2022-11-05 02:59:10 -07:00
colin 1742172e6c app: stacked_cores: 53-xx: add a 5:1 buffer
it seems to under-transfer compared to the 3:1 buffers.
this *might* be an issue of drive current -- unclear.
2022-11-04 06:11:08 -07:00
colin 3ebcc550a0 app: stacked_cores: 53-xx: better constrain the interpolation, and plot slope 2022-11-04 06:10:04 -07:00
colin 373c80793f app: stacked_cores: improve the 52-xx plotting/interpolation
it's a little slow :-(
i'd guess the `score` function is the slowest part. can maybe get scipy
to do a dot-product for us?
2022-11-04 03:22:42 -07:00
colin df828b6299 app: stacked_cores: create a plot_53xx and refactor the surroundings
note that the interpolation is very BAD. i need to figure out better
sampling.
2022-11-03 21:21:07 -07:00
colin 4023a67912 app: stacked_cores: ingest 53-xx buffer results 2022-11-03 20:26:17 -07:00
colin aee3796c29 app: stacked_cores: note about preservation 2022-11-03 05:46:58 -07:00
colin a45c0c4324 app: stacked_cores: new 53-xx run, where we buffer differential signals 2022-11-03 05:42:38 -07:00
colin 47189dcc7e app: stacked_cores: 52-xx: complete more or gate parameterizations 2022-11-03 04:39:06 -07:00
7 changed files with 1155 additions and 105 deletions

View File

@ -1,93 +1,17 @@
#!/usr/bin/env python3
from math import sqrt
from natsort import natsorted
import plotly.express as px
from pandas import DataFrame
from stacked_cores_52xx import *
def plot(name: str, x_name: str, y_series: list):
df = DataFrame(data={ x_name: sweep_1d(len(y_series)), "y": y_series })
fig = px.line(df, x=x_name, y="y", title=name)
fig.show()
def eval_series(meas: 'ParameterizedMeas', points: list, y_idx: int = -1):
return [sample_all(meas, *p)[y_idx] for p in points]
def sample_all(meas: 'ParameterizedMeas', a0: float, a1: float) -> tuple:
runs = [extract_transfer_from_meas_rows(r) for r in meas.runs()]
distances = [(distance_to(m, (a0, a1)), m) for m in runs]
return weighted_sum_of_neighbors_by_inv_distance(distances)
def extract_transfer_from_meas_rows(meas_rows: list) -> tuple:
return (meas_rows[0].m[0], meas_rows[0].m[1], meas_rows[1].m[2], meas_rows[2].m[3])
def interpolate(meas: 'ParameterizedMeas', a0: float, a1: float) -> tuple:
"""
this interpolates a point among four neighboring points in 2d.
the implementation only supports 2d, but the technique is extendable to N dim.
"""
rows = [r.m for r in meas.all_rows()]
distances = [(distance_to(m, (a0, a1)), m) for m in rows]
# a0_below_dist, a0_below_val = min(d for d in distances if d[1][0] <= a0)
# a0_above_dist, a0_above_val = min(d for d in distances if d[1][0] >= a0)
# a1_below_dist, a1_below_val = min(d for d in distances if d[1][1] <= a1)
# a1_above_dist, a1_above_val = min(d for d in distances if d[1][1] >= a1)
a0_below = min((d for d in distances if d[1][0] <= a0), default=None)
a0_above = min((d for d in distances if d[1][0] >= a0), default=None)
a1_below = min((d for d in distances if d[1][1] <= a1), default=None)
a1_above = min((d for d in distances if d[1][1] >= a1), default=None)
neighbors = [a for a in [a0_below, a0_above, a1_below, a1_above] if a is not None]
return weighted_sum_of_neighbors_by_inv_distance(neighbors)
def weighted_sum_of_neighbors_by_inv_distance(neighbors: list) -> tuple:
"""
each neighbor is (distance, value).
return a weighted sum of these neighbors, where lower-distance neighbors are more strongly weighted.
"""
D = sum(a[0] for a in neighbors)
weight_n = lambda n: 1/max(n[0], 1e-3) # non-normalized weight for neighbor
W = sum(weight_n(n) for n in neighbors)
weighted_n = lambda n: weighted(n[1], weight_n(n)/W) # normalized weighted contribution for neighbor
return element_sum([weighted_n(n) for n in neighbors])
def weighted_sum_of_neighbors(neighbors: list) -> tuple:
"""
each neighbor is (distance, value).
return a weighted sum of these neighbors, where lower-distance neighbors are more strongly weighted.
"""
D = sum(a[0] for a in neighbors)
weight_n = lambda n: D - n[0] # non-normalized weight for neighbor
W = sum(weight_n(n) for n in neighbors)
weighted_n = lambda n: weighted(n[1], weight_n(n)/W) # normalized weighted contribution for neighbor
return element_sum([weighted_n(n) for n in neighbors])
def distance_to(p0: tuple, p1: tuple) -> float:
return sqrt(sum((x0-x1)*(x0-x1) for (x0, x1) in zip(p0, p1)))
def element_sum(lists: list) -> list:
elems = lists[0]
for l in lists[1:]:
for i, e in enumerate(l):
elems[i] += e
return elems
def weighted(l: list, scale: float) -> list:
return [e*scale for e in l]
from stacked_cores_52xx_plotters import *
or_gates = DB
or_gates = read_db(lambda name: name.startswith("52-"))
sweep_1d = lambda points=101: [unit_to_m(x/(points-1)) for x in range(points)]
sweep_a0 = lambda a1, points=101: [(unit_to_m(x/(points-1)), a1) for x in range(points)]
sweep_a1 = lambda a0, points=101: [(a0, unit_to_m(x/(points-1))) for x in range(points)]
sweep_a0 = lambda a1, points=101: [(unit_to_m(x/(points-1)), a1, None, None) for x in range(points)]
sweep_a1 = lambda a0, points=101: [(a0, unit_to_m(x/(points-1)), None, None) for x in range(points)]
unit_to_m = lambda u: -17000 + 34000 * u
for name, meas in natsorted(or_gates.items()):
trace = eval_series(meas, sweep_a1(-17000))
trace = eval_series(meas, sweep_a1(-17000), extract_52xx_tx)
plot(f"{name}", "a1", trace)

View File

@ -0,0 +1,20 @@
#!/usr/bin/env python3
from stacked_cores_52xx import *
from stacked_cores_52xx_plotters import *
def extract_53xx_tx(meas_rows: list) -> tuple:
"""
extracts a flat list of input/output M mappings from a 53xx run
"""
return (meas_rows[1].m[0], meas_rows[0].m[1], meas_rows[0].m[2], meas_rows[1].m[3])
sweep_buf_inputs = lambda points=101: [(None, m, -m, None) for m in sweep_1d(points)]
buf_gates = read_db(lambda name: name.startswith("53-"))
for name, meas in natsorted(buf_gates.items()):
print(name)
trace = eval_series(meas, sweep_buf_inputs(), extract_53xx_tx, y_idx=0)
plot(name, "a0", trace)
plot_slope(f"slope {name}", "a0", trace)

View File

@ -8,28 +8,54 @@ from extract_meas import extract_parameterized_meas, indented
from stacked_cores_52xx_db import DB
def extract_stems(dirlist: list) -> list:
stems = set()
TERM = "-drive-"
for d in dirlist:
print(d)
if not d.startswith("52-"): continue
if TERM not in d: continue
stem = d[:d.find(TERM) + len(TERM)]
stems.add(stem)
## CONSTANTS/CONFIGURATION
return stems
# list of sims to extract details for
PREFIXES = { "52", "53" }
def times_of_interest(sim_name: str) -> list:
# could be more intelligent, extracting e.g. the clock duration from the name
if sim_name.startswith("52-"):
return [2e-9, 4e-9, 8e-9]
if sim_name.startswith("53-"):
return [2e-9, 4e-9]
## USER-FACING FUNCTIONS
def read_db(name_filter=lambda name: True) -> dict:
return { name: meas for (name, meas) in DB.items() if name_filter(name) }
def update_db():
db = compute_db()
dump("stacked_cores_52xx_db.py", db)
## IMPLEMENTATION DETAILS
def compute_db():
here, _ = os.path.split(__file__)
toplevel_out = f"{here}/../../../../out/applications/stacked_cores"
stems = extract_stems(os.listdir(toplevel_out))
return {
s: extract_parameterized_meas(os.path.join(toplevel_out, s), [2e-9, 4e-9, 8e-9])
s: extract_parameterized_meas(os.path.join(toplevel_out, s), times_of_interest(s))
for s in stems
}
def extract_stems(dirlist: list) -> list:
stems = set()
TERM = "-drive-"
for d in dirlist:
print(d)
header = d.split('-')[0]
if header not in PREFIXES: continue
if TERM not in d: continue
stem = d[:d.find(TERM) + len(TERM)]
stems.add(stem)
return stems
def dump(path: str, db: dict):
with open(path, "w") as f:
f.write("from extract_meas import MeasRow, ParameterizedMeas\n\n")
@ -38,8 +64,4 @@ def dump(path: str, db: dict):
f.write(indented(f"\n{k!r}: {v},"))
f.write("\n}")
def update_db():
db = compute_db()
dump("stacked_cores_52xx_db.py", db)
if __name__ == '__main__': update_db()

View File

@ -104,6 +104,11 @@ DB = {
MeasRow(4e-09, [-28702, -28186, -5242, -16507]),
MeasRow(8e-09, [-28289, -28206, -28068, 1497]),
],
(-1.000, -0.150,): [
MeasRow(2e-09, [-16878, -3233, -16971, -16915]),
MeasRow(4e-09, [-28719, -28154, -4295, -16590]),
MeasRow(8e-09, [-28286, -28204, -28069, 1958]),
],
(-1.000, -0.100,): [
MeasRow(2e-09, [-16877, -36, -17024, -16921]),
MeasRow(4e-09, [-28738, -28130, -3343, -16636]),
@ -140,6 +145,28 @@ DB = {
MeasRow(8e-09, [-28247, -28189, -28062, 7201]),
],
}),
'52-or--0.0004rad-2000ctl_cond-20000coupling_cond-2000ps-100ps-2ctl-2coupling-7_1_winding-30000001024e0-drive-': ParameterizedMeas({
(-1.000, -1.000,): [
MeasRow(2e-09, [-16784, -16572, -15238, -16832]),
MeasRow(4e-09, [-27082, -26269, -7792, -13485]),
MeasRow(8e-09, [-26419, -26372, -25473, -68]),
],
(-1.000, -0.400,): [
MeasRow(2e-09, [-16768, -13710, -15778, -16825]),
MeasRow(4e-09, [-27241, -25956, -7338, -13706]),
MeasRow(8e-09, [-26422, -26363, -25474, 33]),
],
(-1.000, -0.200,): [
MeasRow(2e-09, [-16784, -7641, -16174, -16839]),
MeasRow(4e-09, [-27589, -25653, -5838, -14151]),
MeasRow(8e-09, [-26420, -26338, -25481, 476]),
],
(-1.000, 1.000,): [
MeasRow(2e-09, [-16713, 16489, -16802, -16806]),
MeasRow(4e-09, [-27986, -25489, 289, -16059]),
MeasRow(8e-09, [-26407, -26276, -25475, 2488]),
],
}),
'52-or--0.0004rad-2000ctl_cond-20000coupling_cond-2000ps-100ps-3ctl-3coupling-3_1_winding-1e10-drive-': ParameterizedMeas({
(-1.000, -1.000,): [
MeasRow(2e-09, [-16757, -16650, -9580, -16753]),
@ -236,6 +263,35 @@ DB = {
MeasRow(8e-09, [-29244, -29165, -29077, 13189]),
],
}),
'52-or--0.0004rad-2000ctl_cond-20000coupling_cond-2000ps-100ps-3ctl-3coupling-5_1_winding-30000001024e0-drive-': ParameterizedMeas({
(-1.000, -1.000,): [
MeasRow(2e-09, [-17460, -18158, -19493, -17147]),
MeasRow(4e-09, [-29302, -29222, -10762, -15087]),
MeasRow(8e-09, [-29179, -29133, -29025, 4845]),
],
(-1.000, -0.200,): [
MeasRow(2e-09, [-17440, -6589, -19111, -17141]),
MeasRow(4e-09, [-29360, -29092, -6253, -16220]),
MeasRow(8e-09, [-29169, -29125, -29026, 7138]),
],
(-1.000, 1.000,): [
MeasRow(2e-09, [-17250, 16095, -18448, -17038]),
MeasRow(4e-09, [-29467, -29031, 1438, -16641]),
MeasRow(8e-09, [-29154, -29121, -29026, 11444]),
],
}),
'52-or--0.0004rad-2000ctl_cond-20000coupling_cond-2000ps-100ps-6ctl-6coupling-3_1_winding-30000001024e0-drive-': ParameterizedMeas({
(-1.000, -1.000,): [
MeasRow(2e-09, [-17769, -18858, -21664, -17773]),
MeasRow(4e-09, [-30699, -30695, -11819, -16763]),
MeasRow(8e-09, [-30676, -30659, -30650, 5721]),
],
(-1.000, 1.000,): [
MeasRow(2e-09, [-17518, 15942, -19734, -17487]),
MeasRow(4e-09, [-30702, -30669, 1327, -16839]),
MeasRow(8e-09, [-30668, -30653, -30648, 15220]),
],
}),
'52-or--0.0004rad-5000ctl_cond-20000coupling_cond-2000ps-100ps-3ctl-3coupling-3_1_winding-30000001024e0-drive-': ParameterizedMeas({
(-1.000, -1.000,): [
MeasRow(2e-09, [-17215, -17627, -18647, -17200]),
@ -345,4 +401,620 @@ DB = {
MeasRow(8e-09, [-30540, -30556, -30463, 11596]),
],
}),
'53-buf--0.0004rad-2000ctl_cond-20000coupling_cond-2000ps-100ps-4ctl-4coupling-5_1_winding-30000001024e0-drive-': ParameterizedMeas({
(-1.000, -1.000,): [
MeasRow(2e-09, [-17730, -20615, -20614, -17732]),
MeasRow(4e-09, [-13368, -28447, -28453, -13380]),
],
(-1.000, 1.000,): [
MeasRow(2e-09, [-17508, -17960, 16995, -17092]),
MeasRow(4e-09, [-16634, -28456, -28448, 4261]),
],
(-0.250, 0.250,): [
MeasRow(2e-09, [-17238, -15983, 16938, -17147]),
MeasRow(4e-09, [-16524, -28453, -28449, 3419]),
],
(-0.220, 0.220,): [
MeasRow(2e-09, [-17226, -14250, 16383, -17220]),
MeasRow(4e-09, [-16081, -28449, -28446, 2449]),
],
(-0.200, -0.200,): [
MeasRow(2e-09, [-17278, -3920, -4057, -17280]),
MeasRow(4e-09, [ -9467, -28449, -28454, -9560]),
],
(-0.200, 0.200,): [
MeasRow(2e-09, [-17245, -12380, 15802, -17275]),
MeasRow(4e-09, [-15313, -28447, -28445, 1429]),
],
(-0.170, 0.170,): [
MeasRow(2e-09, [-17268, -9550, 14257, -17292]),
MeasRow(4e-09, [-13980, -28448, -28448, -282]),
],
(-0.150, 0.150,): [
MeasRow(2e-09, [-17271, -7695, 12547, -17291]),
MeasRow(4e-09, [-13036, -28449, -28449, -1612]),
],
(-0.120, 0.120,): [
MeasRow(2e-09, [-17273, -5017, 10005, -17289]),
MeasRow(4e-09, [-11754, -28449, -28448, -3434]),
],
(-0.100, -0.300,): [
MeasRow(2e-09, [-17287, 3539, -12784, -17273]),
MeasRow(4e-09, [ -3974, -28445, -28454, -14017]),
],
(-0.100, -0.100,): [
MeasRow(2e-09, [-17280, -1, -52, -17282]),
MeasRow(4e-09, [ -8685, -28446, -28452, -8721]),
],
(-0.100, 0.100,): [
MeasRow(2e-09, [-17275, -3362, 8453, -17287]),
MeasRow(4e-09, [-11027, -28448, -28446, -4474]),
],
(-0.070, 0.070,): [
MeasRow(2e-09, [-17277, -1396, 6564, -17285]),
MeasRow(4e-09, [-10182, -28447, -28449, -5662]),
],
(-0.050, -0.200,): [
MeasRow(2e-09, [-17285, 3972, -6987, -17276]),
MeasRow(4e-09, [ -5404, -28445, -28455, -11867]),
],
(-0.050, 0.050,): [
MeasRow(2e-09, [-17277, -262, 5483, -17284]),
MeasRow(4e-09, [ -9651, -28447, -28451, -6338]),
],
(-0.020, 0.020,): [
MeasRow(2e-09, [-17279, 1532, 3855, -17283]),
MeasRow(4e-09, [ -8738, -28446, -28448, -7375]),
],
( 0.000, -0.100,): [
MeasRow(2e-09, [-17282, 4246, -1577, -17280]),
MeasRow(4e-09, [ -6504, -28444, -28454, -10022]),
],
( 0.000, 0.000,): [
MeasRow(2e-09, [-17279, 2719, 2722, -17282]),
MeasRow(4e-09, [ -8066, -28445, -28450, -8069]),
],
( 0.020, -0.020,): [
MeasRow(2e-09, [-17280, 3852, 1531, -17282]),
MeasRow(4e-09, [ -7381, -28445, -28451, -8747]),
],
( 0.050, -0.050,): [
MeasRow(2e-09, [-17282, 5484, -269, -17280]),
MeasRow(4e-09, [ -6349, -28446, -28452, -9664]),
],
( 0.070, -0.070,): [
MeasRow(2e-09, [-17282, 6563, -1408, -17280]),
MeasRow(4e-09, [ -5673, -28446, -28454, -10196]),
],
( 0.100, -0.100,): [
MeasRow(2e-09, [-17285, 8441, -3392, -17278]),
MeasRow(4e-09, [ -4488, -28442, -28455, -11038]),
],
( 0.100, 0.000,): [
MeasRow(2e-09, [-17282, 6932, 1079, -17281]),
MeasRow(4e-09, [ -6084, -28445, -28451, -9332]),
],
( 0.100, 0.100,): [
MeasRow(2e-09, [-17280, 5464, 5494, -17282]),
MeasRow(4e-09, [ -7568, -28446, -28451, -7555]),
],
( 0.120, -0.120,): [
MeasRow(2e-09, [-17287, 9985, -5053, -17277]),
MeasRow(4e-09, [ -3458, -28444, -28455, -11747]),
],
( 0.150, -0.150,): [
MeasRow(2e-09, [-17290, 12519, -7744, -17274]),
MeasRow(4e-09, [ -1639, -28445, -28456, -13034]),
],
( 0.170, -0.170,): [
MeasRow(2e-09, [-17291, 14227, -9605, -17271]),
MeasRow(4e-09, [ -315, -28444, -28456, -13979]),
],
( 0.200, -0.200,): [
MeasRow(2e-09, [-17274, 15790, -12443, -17248]),
MeasRow(4e-09, [ 1403, -28440, -28454, -15316]),
],
( 0.200, -0.100,): [
MeasRow(2e-09, [-17290, 14333, -5906, -17273]),
MeasRow(4e-09, [ -1424, -28443, -28454, -12474]),
],
( 0.200, 0.000,): [
MeasRow(2e-09, [-17288, 12492, -846, -17278]),
MeasRow(4e-09, [ -3437, -28446, -28453, -10471]),
],
( 0.200, 0.100,): [
MeasRow(2e-09, [-17285, 10693, 3854, -17280]),
MeasRow(4e-09, [ -5079, -28446, -28449, -8915]),
],
( 0.220, -0.220,): [
MeasRow(2e-09, [-17221, 16374, -14318, -17229]),
MeasRow(4e-09, [ 2429, -28440, -28456, -16084]),
],
( 0.250, -0.250,): [
MeasRow(2e-09, [-17148, 16918, -16016, -17244]),
MeasRow(4e-09, [ 3380, -28443, -28459, -16520]),
],
( 0.300, -0.300,): [
MeasRow(2e-09, [-17121, 17032, -16821, -17316]),
MeasRow(4e-09, [ 3741, -28443, -28458, -16566]),
],
( 0.300, -0.200,): [
MeasRow(2e-09, [-17057, 17556, -14827, -17200]),
MeasRow(4e-09, [ 3206, -28444, -28457, -16312]),
],
( 0.300, -0.100,): [
MeasRow(2e-09, [-17130, 17012, -8638, -17218]),
MeasRow(4e-09, [ 594, -28442, -28457, -13784]),
],
( 0.300, 0.000,): [
MeasRow(2e-09, [-17209, 16413, -2945, -17238]),
MeasRow(4e-09, [ -1347, -28438, -28455, -11481]),
],
( 1.000, -1.000,): [
MeasRow(2e-09, [-17092, 16993, -17963, -17509]),
MeasRow(4e-09, [ 4227, -28441, -28462, -16632]),
],
}),
'53-buf--0.0004rad-2000ctl_cond-20000coupling_cond-2000ps-100ps-8ctl-8coupling-3_1_winding-2e10-drive-': ParameterizedMeas({
(-1.000, -1.000,): [
MeasRow(2e-09, [-18843, -22156, -22158, -18842]),
MeasRow(4e-09, [-12972, -30862, -30863, -13000]),
],
(-1.000, 1.000,): [
MeasRow(2e-09, [-18633, -19366, 17476, -17129]),
MeasRow(4e-09, [-16353, -30862, -30866, 13132]),
],
(-0.250, 0.250,): [
MeasRow(2e-09, [-17931, -16176, 17812, -17268]),
MeasRow(4e-09, [-15204, -30864, -30865, 12541]),
],
(-0.220, 0.220,): [
MeasRow(2e-09, [-17819, -14738, 17280, -17417]),
MeasRow(4e-09, [-14319, -30863, -30865, 11815]),
],
(-0.200, -0.200,): [
MeasRow(2e-09, [-17937, -4041, -4102, -17937]),
MeasRow(4e-09, [ -5017, -30864, -30866, -5124]),
],
(-0.200, 0.200,): [
MeasRow(2e-09, [-17830, -12743, 16669, -17567]),
MeasRow(4e-09, [-13135, -30864, -30864, 10878]),
],
(-0.170, 0.170,): [
MeasRow(2e-09, [-17852, -9550, 15683, -17796]),
MeasRow(4e-09, [-11334, -30864, -30865, 9413]),
],
(-0.150, 0.150,): [
MeasRow(2e-09, [-17884, -7426, 14863, -17888]),
MeasRow(4e-09, [-10240, -30863, -30866, 8422]),
],
(-0.120, 0.120,): [
MeasRow(2e-09, [-17924, -4285, 13111, -17941]),
MeasRow(4e-09, [ -8558, -30864, -30866, 6649]),
],
(-0.100, -0.300,): [
MeasRow(2e-09, [-17947, 5128, -14351, -17950]),
MeasRow(4e-09, [ 3826, -30864, -30865, -12572]),
],
(-0.100, -0.100,): [
MeasRow(2e-09, [-17943, 1245, 1215, -17940]),
MeasRow(4e-09, [ -2878, -30864, -30866, -2961]),
],
(-0.100, 0.100,): [
MeasRow(2e-09, [-17936, -2251, 11556, -17952]),
MeasRow(4e-09, [ -7454, -30864, -30865, 5222]),
],
(-0.070, 0.070,): [
MeasRow(2e-09, [-17940, 588, 9078, -17951]),
MeasRow(4e-09, [ -5581, -30864, -30865, 2888]),
],
(-0.050, -0.200,): [
MeasRow(2e-09, [-17949, 5960, -7439, -17935]),
MeasRow(4e-09, [ 2834, -30864, -30865, -9248]),
],
(-0.050, 0.050,): [
MeasRow(2e-09, [-17942, 2189, 7850, -17950]),
MeasRow(4e-09, [ -4270, -30864, -30866, 1560]),
],
(-0.020, 0.020,): [
MeasRow(2e-09, [-17944, 4113, 6275, -17947]),
MeasRow(4e-09, [ -2400, -30864, -30866, -182]),
],
( 0.000, -0.100,): [
MeasRow(2e-09, [-17951, 6613, -553, -17938]),
MeasRow(4e-09, [ 1592, -30864, -30866, -5794]),
],
( 0.000, 0.000,): [
MeasRow(2e-09, [-17948, 5240, 5238, -17947]),
MeasRow(4e-09, [ -1241, -30864, -30865, -1304]),
],
( 0.020, -0.020,): [
MeasRow(2e-09, [-17948, 6275, 4110, -17942]),
MeasRow(4e-09, [ -120, -30865, -30866, -2461]),
],
( 0.050, -0.050,): [
MeasRow(2e-09, [-17952, 7847, 2182, -17940]),
MeasRow(4e-09, [ 1606, -30864, -30865, -4295]),
],
( 0.070, -0.070,): [
MeasRow(2e-09, [-17953, 9073, 578, -17939]),
MeasRow(4e-09, [ 2911, -30863, -30866, -5554]),
],
( 0.100, -0.100,): [
MeasRow(2e-09, [-17953, 11548, -2267, -17936]),
MeasRow(4e-09, [ 5222, -30864, -30865, -7387]),
],
( 0.100, 0.000,): [
MeasRow(2e-09, [-17952, 9502, 3879, -17943]),
MeasRow(4e-09, [ 2250, -30863, -30866, -3593]),
],
( 0.100, 0.100,): [
MeasRow(2e-09, [-17949, 8069, 8091, -17947]),
MeasRow(4e-09, [ -133, -30864, -30866, -179]),
],
( 0.120, -0.120,): [
MeasRow(2e-09, [-17942, 13103, -4303, -17924]),
MeasRow(4e-09, [ 6658, -30865, -30866, -8519]),
],
( 0.150, -0.150,): [
MeasRow(2e-09, [-17891, 14856, -7448, -17884]),
MeasRow(4e-09, [ 8441, -30864, -30865, -10248]),
],
( 0.170, -0.170,): [
MeasRow(2e-09, [-17800, 15679, -9574, -17852]),
MeasRow(4e-09, [ 9435, -30863, -30866, -11346]),
],
( 0.200, -0.200,): [
MeasRow(2e-09, [-17571, 16665, -12771, -17830]),
MeasRow(4e-09, [ 10904, -30863, -30865, -13164]),
],
( 0.200, -0.100,): [
MeasRow(2e-09, [-17767, 15815, -4875, -17851]),
MeasRow(4e-09, [ 8529, -30863, -30866, -9055]),
],
( 0.200, 0.000,): [
MeasRow(2e-09, [-17890, 14834, 2082, -17891]),
MeasRow(4e-09, [ 6256, -30865, -30865, -5462]),
],
( 0.200, 0.100,): [
MeasRow(2e-09, [-17923, 13988, 6476, -17920]),
MeasRow(4e-09, [ 4573, -30865, -30866, -2955]),
],
( 0.220, -0.220,): [
MeasRow(2e-09, [-17422, 17276, -14769, -17819]),
MeasRow(4e-09, [ 11842, -30864, -30865, -14353]),
],
( 0.250, -0.250,): [
MeasRow(2e-09, [-17272, 17806, -16195, -17933]),
MeasRow(4e-09, [ 12564, -30864, -30866, -15233]),
],
( 0.300, -0.300,): [
MeasRow(2e-09, [-17247, 17609, -17421, -18163]),
MeasRow(4e-09, [ 12737, -30864, -30866, -15929]),
],
( 0.300, -0.200,): [
MeasRow(2e-09, [-17189, 18283, -14362, -17797]),
MeasRow(4e-09, [ 12494, -30865, -30864, -14240]),
],
( 0.300, -0.100,): [
MeasRow(2e-09, [-17223, 18128, -7478, -17801]),
MeasRow(4e-09, [ 10788, -30864, -30865, -10541]),
],
( 0.300, 0.000,): [
MeasRow(2e-09, [-17359, 17488, -256, -17822]),
MeasRow(4e-09, [ 8739, -30864, -30865, -6837]),
],
( 1.000, -1.000,): [
MeasRow(2e-09, [-17130, 17473, -19369, -18634]),
MeasRow(4e-09, [ 13152, -30864, -30864, -16361]),
],
}),
'53-buf--0.0004rad-2000ctl_cond-20000coupling_cond-2000ps-100ps-8ctl-8coupling-3_1_winding-30000001024e0-drive-': ParameterizedMeas({
(-1.000, -1.000,): [
MeasRow(2e-09, [-18974, -22341, -22343, -18973]),
MeasRow(4e-09, [-11991, -31210, -31210, -12021]),
],
(-1.000, 1.000,): [
MeasRow(2e-09, [-18799, -19508, 17570, -17162]),
MeasRow(4e-09, [-16581, -31210, -31209, 15188]),
],
(-0.250, 0.250,): [
MeasRow(2e-09, [-18555, -18849, 17145, -17361]),
MeasRow(4e-09, [-16508, -31209, -31211, 14859]),
],
(-0.220, 0.220,): [
MeasRow(2e-09, [-18404, -18072, 17368, -17358]),
MeasRow(4e-09, [-16424, -31209, -31211, 14835]),
],
(-0.200, -0.200,): [
MeasRow(2e-09, [-18065, -9423, -9528, -18062]),
MeasRow(4e-09, [ -6035, -31210, -31213, -6179]),
],
(-0.200, 0.200,): [
MeasRow(2e-09, [-18271, -17413, 17570, -17353]),
MeasRow(4e-09, [-16342, -31209, -31211, 14821]),
],
(-0.170, 0.170,): [
MeasRow(2e-09, [-18069, -16325, 17787, -17367]),
MeasRow(4e-09, [-16157, -31209, -31210, 14701]),
],
(-0.150, 0.150,): [
MeasRow(2e-09, [-17949, -15084, 17422, -17490]),
MeasRow(4e-09, [-15534, -31206, -31210, 14103]),
],
(-0.120, 0.120,): [
MeasRow(2e-09, [-17972, -10612, 16063, -17819]),
MeasRow(4e-09, [-12596, -31209, -31209, 11784]),
],
(-0.100, -0.300,): [
MeasRow(2e-09, [-18067, 5167, -20131, -18852]),
MeasRow(4e-09, [ 7226, -31209, -31209, -16382]),
],
(-0.100, -0.100,): [
MeasRow(2e-09, [-18068, -1253, -1303, -18064]),
MeasRow(4e-09, [ -2761, -31208, -31210, -2848]),
],
(-0.100, 0.100,): [
MeasRow(2e-09, [-18007, -7418, 14962, -17991]),
MeasRow(4e-09, [-10486, -31209, -31210, 10122]),
],
(-0.070, 0.070,): [
MeasRow(2e-09, [-18061, -2730, 12268, -18067]),
MeasRow(4e-09, [ -7310, -31208, -31211, 7142]),
],
(-0.050, -0.200,): [
MeasRow(2e-09, [-18070, 6628, -14729, -18088]),
MeasRow(4e-09, [ 6652, -31209, -31208, -13582]),
],
(-0.050, 0.050,): [
MeasRow(2e-09, [-18066, 181, 9808, -18069]),
MeasRow(4e-09, [ -4971, -31208, -31210, 4642]),
],
(-0.020, 0.020,): [
MeasRow(2e-09, [-18068, 3737, 7127, -18069]),
MeasRow(4e-09, [ -1801, -31209, -31211, 1658]),
],
( 0.000, -0.100,): [
MeasRow(2e-09, [-18074, 7689, -4284, -18062]),
MeasRow(4e-09, [ 4493, -31209, -31211, -7374]),
],
( 0.000, 0.000,): [
MeasRow(2e-09, [-18071, 5550, 5555, -18069]),
MeasRow(4e-09, [ -9, -31208, -31210, -47]),
],
( 0.020, -0.020,): [
MeasRow(2e-09, [-18072, 7122, 3737, -18066]),
MeasRow(4e-09, [ 1698, -31209, -31210, -1839]),
],
( 0.050, -0.050,): [
MeasRow(2e-09, [-18074, 9800, 172, -18064]),
MeasRow(4e-09, [ 4672, -31208, -31210, -5002]),
],
( 0.070, -0.070,): [
MeasRow(2e-09, [-18071, 12255, -2744, -18059]),
MeasRow(4e-09, [ 7159, -31210, -31210, -7320]),
],
( 0.100, -0.100,): [
MeasRow(2e-09, [-17996, 14953, -7439, -18005]),
MeasRow(4e-09, [ 10137, -31209, -31212, -10490]),
],
( 0.100, 0.000,): [
MeasRow(2e-09, [-18065, 12754, 3295, -18059]),
MeasRow(4e-09, [ 5851, -31210, -31210, -3696]),
],
( 0.100, 0.100,): [
MeasRow(2e-09, [-18070, 10402, 10444, -18067]),
MeasRow(4e-09, [ 1942, -31208, -31209, 1929]),
],
( 0.120, -0.120,): [
MeasRow(2e-09, [-17825, 16056, -10639, -17969]),
MeasRow(4e-09, [ 11806, -31208, -31211, -12618]),
],
( 0.150, -0.150,): [
MeasRow(2e-09, [-17496, 17416, -15114, -17947]),
MeasRow(4e-09, [ 14124, -31209, -31209, -15552]),
],
( 0.170, -0.170,): [
MeasRow(2e-09, [-17371, 17782, -16343, -18070]),
MeasRow(4e-09, [ 14720, -31209, -31211, -16168]),
],
( 0.200, -0.200,): [
MeasRow(2e-09, [-17356, 17565, -17433, -18272]),
MeasRow(4e-09, [ 14847, -31209, -31211, -16356]),
],
( 0.200, -0.100,): [
MeasRow(2e-09, [-17305, 18200, -10951, -17925]),
MeasRow(4e-09, [ 13576, -31209, -31211, -13128]),
],
( 0.200, 0.000,): [
MeasRow(2e-09, [-17461, 17492, -152, -17948]),
MeasRow(4e-09, [ 10241, -31209, -31210, -6527]),
],
( 0.200, 0.100,): [
MeasRow(2e-09, [-17648, 16708, 7450, -17968]),
MeasRow(4e-09, [ 7623, -31208, -31211, -1884]),
],
( 0.220, -0.220,): [
MeasRow(2e-09, [-17361, 17362, -18093, -18406]),
MeasRow(4e-09, [ 14863, -31209, -31211, -16438]),
],
( 0.250, -0.250,): [
MeasRow(2e-09, [-17364, 17143, -18859, -18554]),
MeasRow(4e-09, [ 14888, -31209, -31211, -16520]),
],
( 0.300, -0.300,): [
MeasRow(2e-09, [-17347, 17126, -19106, -18618]),
MeasRow(4e-09, [ 14928, -31209, -31210, -16546]),
],
( 0.300, -0.200,): [
MeasRow(2e-09, [-17302, 17776, -17407, -18279]),
MeasRow(4e-09, [ 14986, -31209, -31211, -16359]),
],
( 0.300, -0.100,): [
MeasRow(2e-09, [-17221, 18517, -11325, -17922]),
MeasRow(4e-09, [ 13930, -31209, -31210, -13404]),
],
( 0.300, 0.000,): [
MeasRow(2e-09, [-17218, 18508, -2343, -17929]),
MeasRow(4e-09, [ 11588, -31209, -31210, -7913]),
],
( 1.000, -1.000,): [
MeasRow(2e-09, [-17161, 17565, -19511, -18800]),
MeasRow(4e-09, [ 15203, -31209, -31211, -16592]),
],
}),
'53-buf--0.0004rad-2000ctl_cond-20000coupling_cond-2000ps-100ps-13ctl-13coupling-1_1_winding-30000001024e0-drive-': ParameterizedMeas({
(-1.000, -1.000,): [
MeasRow(2e-09, [-20249, -21908, -21908, -20249]),
MeasRow(4e-09, [-10325, -32229, -32230, -10338]),
],
(-1.000, 1.000,): [
MeasRow(2e-09, [-19998, -19494, 16658, -17591]),
MeasRow(4e-09, [-13753, -32226, -32225, 14257]),
],
(-0.250, 0.250,): [
MeasRow(2e-09, [-19623, -19193, 16163, -17986]),
MeasRow(4e-09, [-13226, -32226, -32226, 13624]),
],
(-0.220, 0.220,): [
MeasRow(2e-09, [-19600, -19170, 16119, -18023]),
MeasRow(4e-09, [-13189, -32226, -32227, 13568]),
],
(-0.200, -0.200,): [
MeasRow(2e-09, [-19875, -20606, -20619, -19875]),
MeasRow(4e-09, [ -9437, -32228, -32229, -9453]),
],
(-0.200, 0.200,): [
MeasRow(2e-09, [-19585, -19148, 16085, -18050]),
MeasRow(4e-09, [-13162, -32226, -32227, 13524]),
],
(-0.170, 0.170,): [
MeasRow(2e-09, [-19558, -19103, 16030, -18096]),
MeasRow(4e-09, [-13108, -32226, -32226, 13449]),
],
(-0.150, 0.150,): [
MeasRow(2e-09, [-19532, -19059, 15998, -18127]),
MeasRow(4e-09, [-13058, -32226, -32226, 13398]),
],
(-0.120, 0.120,): [
MeasRow(2e-09, [-19265, -18179, 16261, -18117]),
MeasRow(4e-09, [-12413, -32226, -32226, 13436]),
],
(-0.100, -0.300,): [
MeasRow(2e-09, [-18977, -2453, -20395, -20234]),
MeasRow(4e-09, [ 1929, -32228, -32228, -12050]),
],
(-0.100, -0.100,): [
MeasRow(2e-09, [-19009, -7247, -7278, -19008]),
MeasRow(4e-09, [ -2908, -32225, -32226, -2940]),
],
(-0.100, 0.100,): [
MeasRow(2e-09, [-18954, -16638, 16600, -18120]),
MeasRow(4e-09, [-11372, -32224, -32226, 13411]),
],
(-0.070, 0.070,): [
MeasRow(2e-09, [-18913, -11406, 16557, -18117]),
MeasRow(4e-09, [ -8376, -32224, -32226, 12581]),
],
(-0.050, -0.200,): [
MeasRow(2e-09, [-18995, 8385, -20274, -20168]),
MeasRow(4e-09, [ 8411, -32226, -32227, -13340]),
],
(-0.050, 0.050,): [
MeasRow(2e-09, [-18938, -5052, 15561, -18542]),
MeasRow(4e-09, [ -4664, -32225, -32225, 10663]),
],
(-0.020, 0.020,): [
MeasRow(2e-09, [-19008, 4596, 13221, -18962]),
MeasRow(4e-09, [ 1073, -32223, -32226, 7438]),
],
( 0.000, -0.100,): [
MeasRow(2e-09, [-18947, 13727, -14811, -19001]),
MeasRow(4e-09, [ 10851, -32225, -32225, -10094]),
],
( 0.000, 0.000,): [
MeasRow(2e-09, [-19032, 10161, 10159, -19031]),
MeasRow(4e-09, [ 4740, -32222, -32224, 4737]),
],
( 0.020, -0.020,): [
MeasRow(2e-09, [-18964, 13216, 4594, -19008]),
MeasRow(4e-09, [ 7435, -32225, -32225, 1066]),
],
( 0.050, -0.050,): [
MeasRow(2e-09, [-18544, 15564, -5056, -18936]),
MeasRow(4e-09, [ 10673, -32224, -32226, -4685]),
],
( 0.070, -0.070,): [
MeasRow(2e-09, [-18117, 16560, -11417, -18912]),
MeasRow(4e-09, [ 12602, -32225, -32225, -8409]),
],
( 0.100, -0.100,): [
MeasRow(2e-09, [-18121, 16599, -16645, -18952]),
MeasRow(4e-09, [ 13432, -32225, -32226, -11403]),
],
( 0.100, 0.000,): [
MeasRow(2e-09, [-18013, 16704, 4312, -18932]),
MeasRow(4e-09, [ 10288, -32224, -32225, 561]),
],
( 0.100, 0.100,): [
MeasRow(2e-09, [-18234, 16560, 16555, -18232]),
MeasRow(4e-09, [ 8278, -32223, -32224, 8264]),
],
( 0.120, -0.120,): [
MeasRow(2e-09, [-18118, 16261, -18185, -19264]),
MeasRow(4e-09, [ 13456, -32225, -32227, -12439]),
],
( 0.150, -0.150,): [
MeasRow(2e-09, [-18128, 15999, -19058, -19530]),
MeasRow(4e-09, [ 13417, -32226, -32227, -13080]),
],
( 0.170, -0.170,): [
MeasRow(2e-09, [-18095, 16031, -19103, -19556]),
MeasRow(4e-09, [ 13467, -32226, -32227, -13132]),
],
( 0.200, -0.200,): [
MeasRow(2e-09, [-18051, 16085, -19149, -19582]),
MeasRow(4e-09, [ 13543, -32226, -32227, -13184]),
],
( 0.200, -0.100,): [
MeasRow(2e-09, [-17960, 16889, -16571, -18961]),
MeasRow(4e-09, [ 13714, -32225, -32226, -11400]),
],
( 0.200, 0.000,): [
MeasRow(2e-09, [-17829, 17055, 3172, -18929]),
MeasRow(4e-09, [ 10825, -32224, -32225, -108]),
],
( 0.200, 0.100,): [
MeasRow(2e-09, [-17776, 17669, 16584, -18303]),
MeasRow(4e-09, [ 9288, -32224, -32224, 8100]),
],
( 0.220, -0.220,): [
MeasRow(2e-09, [-18025, 16119, -19171, -19598]),
MeasRow(4e-09, [ 13585, -32226, -32227, -13214]),
],
( 0.250, -0.250,): [
MeasRow(2e-09, [-17988, 16157, -19194, -19621]),
MeasRow(4e-09, [ 13640, -32226, -32227, -13249]),
],
( 0.300, -0.300,): [
MeasRow(2e-09, [-17935, 16219, -19225, -19657]),
MeasRow(4e-09, [ 13721, -32226, -32227, -13302]),
],
( 0.300, -0.200,): [
MeasRow(2e-09, [-17949, 16265, -19080, -19588]),
MeasRow(4e-09, [ 13716, -32226, -32227, -13170]),
],
( 0.300, -0.100,): [
MeasRow(2e-09, [-17864, 17045, -16615, -18974]),
MeasRow(4e-09, [ 13886, -32225, -32226, -11451]),
],
( 0.300, 0.000,): [
MeasRow(2e-09, [-17730, 17221, 2408, -18930]),
MeasRow(4e-09, [ 11123, -32225, -32225, -561]),
],
( 1.000, -1.000,): [
MeasRow(2e-09, [-17594, 16657, -19494, -19998]),
MeasRow(4e-09, [ 14276, -32225, -32228, -13778]),
],
}),
}

View File

@ -0,0 +1,172 @@
from math import sqrt
import plotly.express as px
from pandas import DataFrame
import scipy.optimize as opt
unit_to_m = lambda u: -17000 + 34000 * u
sweep_1d = lambda points=101: [unit_to_m(x/(points-1)) for x in range(points)]
def plot(name: str, x_name: str, y_series: list):
""" plot y(x), where y values are specified by `y_series` and x is inferred """
df = DataFrame(data={ x_name: sweep_1d(len(y_series)), "y": y_series })
fig = px.line(df, x=x_name, y="y", title=name)
fig.show()
def plot_slope(name: str, x_name: str, y_series: list):
slope = extract_slope(y_series)
plot(name, x_name, slope)
def extract_slope(y_series: list):
dist = 2 * 34000 / (len(y_series) - 1)
known = [ (next - prev)/dist for (prev, next) in zip(y_series[:-2], y_series[2:]) ]
return [known[0]] + known + [known[-1]]
def eval_series(meas: 'ParameterizedMeas', points: list, extract_tx, y_idx: int = -1) -> list:
"""
extract a list of y-value floats from `meas`.
each x value is a tuple of desired M values at which to sample the curve.
e.g. points = [ (None, 1000.0, 2000.0, None) ] samples at M1=1000.0, M2=2000.0,
treating M0 and M3 as dependent values.
`y_idx` specifies which M value should be treated as the dependent value to be computed.
e.g. `y_idx=0` to compute M0.
`extract_tx` is a function mapping one run (list[list[float]] of M values)
to a measured point of the transfer function. e.g. [15000, -15000, 14000] for a 3-core OR gate.
"""
return [sample_all(meas, p, extract_tx)[y_idx] for p in points]
def sample_all(meas: 'ParameterizedMeas', at: tuple, extract_tx) -> tuple:
"""
computes the interpolated M values at the provided `at` coordinate;
effectively fillin in whichever items in `at` are left at `None`
"""
runs = [extract_tx(r) for r in meas.runs()]
distances = [(distance_to_sq(m, at), m) for m in runs]
# interpolated = weighted_sum_of_neighbors_by_inv_distance(distances)
interpolated = interpolate_minl1(at, runs, distances)
print(at, interpolated)
return interpolated
def extract_52xx_tx(meas_rows: list) -> tuple:
"""
extracts a flat list of input/output M mappings from a 52xx run
"""
return (meas_rows[0].m[0], meas_rows[0].m[1], meas_rows[1].m[2], meas_rows[2].m[3])
def interpolate_minl1(at: tuple, runs: list, distances: list) -> tuple:
# let R = `runs`, A = `at`, D = `distances`, x be the weight of each run
# such that the result is R0 x0 + R1 x1 + ...
#
# solve for x
# subject to R0 x0 + R1 x1 + ... = A for the elements of A != None
# minimize D0 x0 + D1 x1 + ...
#
# relevant scipy docs:
# - <https://docs.scipy.org/doc/scipy/tutorial/optimize.html#trust-region-constrained-algorithm-method-trust-constr>
# - <https://docs.scipy.org/doc/scipy-0.18.1/reference/generated/scipy.optimize.minimize.html>
fixed_coords = [(i, a) for (i, a) in enumerate(at) if a is not None]
num_fixed_coords = len(fixed_coords)
num_runs = len(runs)
# create a matrix E, where E*x = A for Ai != None
eq_constraints = [[0]*num_runs for _ in range(num_fixed_coords)]
for run_idx, run in enumerate(runs):
for constraint_idx, (coord_idx, _a) in enumerate(fixed_coords):
eq_constraints[constraint_idx][run_idx] = run[coord_idx]
eq_rhs = [a for (i, a) in fixed_coords]
eq_constraint = opt.LinearConstraint(eq_constraints, eq_rhs, eq_rhs)
# constrain the sum of weights to be 1.0
weights_sum_to_1_constraint = opt.LinearConstraint([[1] * num_runs], [1], [1])
# constrain the weights to be positive
bounds = opt.Bounds([0]*num_runs, [float("Inf")]*num_runs)
def score(weights: list) -> float:
# function to minimize: D0 x0 + D1 x1 + ...
return sum(w*d[0] for w, d in zip(weights, distances))
# compute the weight of each run
init = [0]*num_runs
constraints = [eq_constraint, weights_sum_to_1_constraint]
res = opt.minimize(score, init, method='trust-constr', constraints=constraints, bounds=bounds)
run_weights = res.x
# sum the weighted runs
return element_sum([weighted(run, weight) for run, weight in zip(runs, run_weights)])
def interpolate(meas: 'ParameterizedMeas', a0: float, a1: float) -> tuple:
"""
this interpolates a point among four neighboring points in 2d.
the implementation only supports 2d, but the technique is extendable to N dim.
"""
rows = [r.m for r in meas.all_rows()]
distances = [(distance_to(m, (a0, a1)), m) for m in rows]
# a0_below_dist, a0_below_val = min(d for d in distances if d[1][0] <= a0)
# a0_above_dist, a0_above_val = min(d for d in distances if d[1][0] >= a0)
# a1_below_dist, a1_below_val = min(d for d in distances if d[1][1] <= a1)
# a1_above_dist, a1_above_val = min(d for d in distances if d[1][1] >= a1)
a0_below = min((d for d in distances if d[1][0] <= a0), default=None)
a0_above = min((d for d in distances if d[1][0] >= a0), default=None)
a1_below = min((d for d in distances if d[1][1] <= a1), default=None)
a1_above = min((d for d in distances if d[1][1] >= a1), default=None)
neighbors = [a for a in [a0_below, a0_above, a1_below, a1_above] if a is not None]
return weighted_sum_of_neighbors_by_inv_distance(neighbors)
def weighted_sum_of_neighbors_by_inv_distance(neighbors: list) -> tuple:
"""
each neighbor is (distance, value).
return a weighted sum of these neighbors, where lower-distance neighbors are more strongly weighted.
"""
D = sum(a[0] for a in neighbors)
weight_n = lambda n: 1/max(n[0], 1e-3) # non-normalized weight for neighbor
W = sum(weight_n(n) for n in neighbors)
weighted_n = lambda n: weighted(n[1], weight_n(n)/W) # normalized weighted contribution for neighbor
return element_sum([weighted_n(n) for n in neighbors])
def weighted_sum_of_neighbors(neighbors: list) -> tuple:
"""
each neighbor is (distance, value).
return a weighted sum of these neighbors, where lower-distance neighbors are more strongly weighted.
"""
D = sum(a[0] for a in neighbors)
weight_n = lambda n: D - n[0] # non-normalized weight for neighbor
W = sum(weight_n(n) for n in neighbors)
weighted_n = lambda n: weighted(n[1], weight_n(n)/W) # normalized weighted contribution for neighbor
return element_sum([weighted_n(n) for n in neighbors])
def distance_to(p0: tuple, p1: tuple) -> float:
"""
return the L2-norm distance from p0 to p1.
any coordinates set to `None` are ignored.
e.g. `distance_to((1, 2, 3), (None, 4, 5))` is the same as `distance_to((2, 3), (4, 5))`
"""
return sqrt(distance_to_sq(p0, p1))
def distance_to_sq(p0: tuple, p1: tuple) -> float:
return sum((x0-x1)*(x0-x1) for (x0, x1) in zip(p0, p1) if x0 is not None and x1 is not None)
def element_sum(lists: list) -> list:
"""
given a list[list[float]] where each inner length is of identical length,
returns a list[float] by summing along each axis.
e.g. element_sum([[1, 2], [3, 4], [5, 6]]) gives `[1+2+5, 2+4+6]`
"""
elems = lists[0]
for l in lists[1:]:
for i, e in enumerate(l):
elems[i] += e
return elems
def weighted(l: list, scale: float) -> list:
"""
given list[float], returns a new list[float] where each element is multipled by `scale`
"""
return [e*scale for e in l]

View File

@ -4,8 +4,13 @@
//! to run this, from toplevel directory:
//! ```
//! $ cargo run --release --bin stacked_cores
//! $ pushd crates/coremem; cargo run --release --bin viewer ../../out/applications/stacked_cores/0/ ; popd
//! $ cargo run --release --bin viewer out/applications/stacked_cores/0/
//! ```
//!
//! this file is a massive collection of related experiments, and i like to be able to
//! re-run/vary/reference earlier experiments -- without hacking the git history -- so there's a
//! lot of stuff in this file, some of it apparently redundant, in order to keep those older
//! experiments working exactly as they originally did.
#![feature(generic_const_exprs)]
use coremem::geom::{Coord as _, Meters};
@ -341,8 +346,10 @@ impl Params {
)
);
// how far to bring the wire past the center of the torus circle
let outside_small = self.s_minor * 2.0;
let outside_large = self.s_minor * 2.0 + self.coupling_minor * 4.0;
// self.s_minor * 2.0 works to dodge the core itself,
// but larger values are required to also dodge direct couplings we might be near to.
let outside_small = self.s_minor * 4.0;
let outside_large = self.s_minor * 4.0 + self.coupling_minor * 4.0;
let outside_top_center_z = self.coupling_major;
let outside_bot_center_z = -self.coupling_major;
let bring_outside_top_small = Cube::new(
@ -1343,6 +1350,20 @@ fn drive_map_or_gate(amp0: f32, amp1: f32) -> [[ClockState; 4]; 4] {
]
}
#[allow(unused)]
fn drive_map_buf_53(amp0: f32, amp1: f32) -> [[ClockState; 4]; 2] {
use ClockState as C;
// amplitudes are inverted from what you would expect.
// hold(-1) puts the core into a positive M
[
// init S1 pos, S2 pos; charge S0 neg, S3 neg
[C::release_high(), C::release(-amp0), C::release(-amp1), C::release_high()],
// clear S1 -> S0, S2 -> S3
[C::float(), C::hold_high(), C::hold_high(), C::float(), ],
]
}
fn asymmetric_inverter_name(p: &Params, sim_id: &str, windings: u32, init_flt: f32) -> String {
let init_int = (init_flt.abs() * 100.0 + 0.5) as u32;
let init_level = if init_flt > 0.0 {
@ -1487,6 +1508,7 @@ fn couple_asymmetric_buffer(params: &Params, sender: u32, loops: u32, slot_offse
let slots_per_asym = 2*loops;
// couple c to c+1
let c1 = c0+1;
// wires which actually connect c0 to c1
let mut params = params
.with_coupling(c0, c1, slot_offset, net_slots, CouplingMethod::direct_half_exterior())
.with_coupling(c0, c1, slot_offset + slots_per_asym - 1, net_slots, CouplingMethod::direct_half_interior())
@ -1514,6 +1536,63 @@ fn couple_asymmetric_buffer(params: &Params, sender: u32, loops: u32, slot_offse
params
}
fn couple_asymmetric_buffer_bi(params: &Params, c0: u32, c0_loops: u32, c1_loops: u32, slot_offset: u32, net_slots: u32) -> Params {
let slots_per_asym = 2*(c0_loops.max(c1_loops));
// couple c to c+1
let c1 = c0+1;
// wires which actually connect c0 to c1
let mut params = params
.with_coupling(c0, c1, slot_offset, net_slots, CouplingMethod::direct_half_exterior())
.with_coupling(c0, c1, slot_offset + slots_per_asym - 1, net_slots, CouplingMethod::direct_half_interior())
;
// loops for sender c0
for i in 0..slots_per_asym {
if i < 2*c0_loops {
if i % 2 == 0 {
// bring up
params = params.with_coupling(c0, c0, slot_offset + i, net_slots, CouplingMethod::SelfLoopHalfInterior);
// bring to next slot
params = params.with_coupling(c0, c0, slot_offset + i, net_slots, CouplingMethod::SelfAngularTop);
} else {
// bring down
params = params.with_coupling(c0, c0, slot_offset + i, net_slots, CouplingMethod::SelfLoopHalfExterior);
if i + 1 != slots_per_asym {
// bring to next slot -- if there is one
params = params.with_coupling(c0, c0, slot_offset + i, net_slots, CouplingMethod::SelfAngularBot);
}
}
} else if i + 1 != slots_per_asym {
// bring to next slot -- if there is one
params = params.with_coupling(c0, c0, slot_offset + i, net_slots, CouplingMethod::SelfAngularBot);
}
}
// loops for receiver c1
for i in 0..slots_per_asym {
if i < 2*c1_loops {
if i % 2 == 0 {
// bring down
params = params.with_coupling(c1, c1, slot_offset + i, net_slots, CouplingMethod::SelfLoopHalfInterior);
// bring to next slot
params = params.with_coupling(c1, c1, slot_offset + i, net_slots, CouplingMethod::SelfAngularBot);
} else {
// bring up
params = params.with_coupling(c1, c1, slot_offset + i, net_slots, CouplingMethod::SelfLoopHalfExterior);
if i + 1 != slots_per_asym {
// bring to next slot -- if there is one
params = params.with_coupling(c1, c1, slot_offset + i, net_slots, CouplingMethod::SelfAngularTop);
}
}
} else if i + 1 != slots_per_asym {
// bring to next slot -- if there is one
params = params.with_coupling(c1, c1, slot_offset + i, net_slots, CouplingMethod::SelfAngularTop);
}
}
params
}
fn main() {
coremem::init_logging();
// coremem::init_debug();
@ -5680,8 +5759,13 @@ fn main() {
}
}
if true {
if false {
for init_set in [
&[
// establish domain/range for M0 fixed at -1
(-1.00, 1.00),
(-1.00, -1.00),
][..],
&[
// targeted
(-1.00, -0.20),
@ -5693,28 +5777,55 @@ fn main() {
(-1.00, -0.15),
(-1.00, -0.25),
(-1.00, -0.50),
(-1.00, 0.20),
][..],
&[
// establish the domain/range
( 1.00, 1.00),
(-1.00, -1.00),
(-1.00, 1.00),
( 1.00, -1.00),
][..],
&[
(0.00, 0.00),
( 0.00, 0.00),
(-1.00, 0.00),
][..],
] {
for (ctl_cond, coupling_cond, clock_duration, clock_decay, coupling_loops, s0_loops, s_major, cur_flt) in [
(5e3, 2e4, ps(2000), ps(100), 3, 1, um(400), 5e10),
(5e2, 2e4, ps(2000), ps(100), 3, 1, um(400), 5e10),
// comments are: discr=<M3 difference for M1=HIGH v.s. M1=LOW>
// then transfer characteristics for (M0, M1) (at t0) => (M2 (at t1), M3 (at t2))
// total slot use count is L*(6*A + 1),
// where L is the "coupling loops" and A is the s0_loops ("asymmetric loops")
// e.g. L=3, A=1 gives 21
// e.g. L=6, A=1 gives 42
// e.g. L=3, A=2 gives 39
// e.g. L=2, A=3 gives 38
// note that the input buffers M0, M1 are coupled 1:1 with M2;
// only M2 is coupled asymmetrically to M3.
// but equal slots are given to both, so 4 asymmetric loops from M2 to M3 implies a
// corresponding 4 symmetric loops from M1 to M2
// discr: 2600 (-1, -1) => (-7800, -100); (-1, 1) => (300, 2500)
(2e3, 2e4, ps(2000), ps(100), 2, 3, um(400), 3e10),
// discr=9500 (-1, -1) => (-11800, 5700); (-1, 1) => (1300, 15200)
(2e3, 2e4, ps(2000), ps(100), 6, 1, um(400), 3e10),
// TODO: unifinished
(2e3, 2e4, ps(2000), ps(100), 6, 1, um(400), 2e10),
// discr=6600: (-1, -1) => (-10800, 4800); (-1, 1) => (1400, 11400)
(2e3, 2e4, ps(2000), ps(100), 3, 2, um(400), 3e10),
// discr=4900: (-1, -1) => (-9400, 8500); (-1, 1) => (1500, 13400)
(5e2, 2e4, ps(2000), ps(100), 3, 1, um(400), 5e10),
// discr=4400: (-1, -1) => (-8600, 200); (-1, 1) => (1100, 4600)
(1e3, 2e4, ps(2000), ps(100), 3, 1, um(400), 2e10),
// discr=1300: (-1, -1) => (-3400, -2300); (-1, 1) => (-100, -1000)
(2e3, 2e4, ps(2000), ps(100), 3, 1, um(400), 1e10),
// discr=5200: (-1, -1) => (-9700, 400); (-1, 1) => (1100, 5600)
(2e3, 2e4, ps(2000), ps(100), 3, 1, um(400), 2e10),
// discr=5300: (-1, -1) => (-9500, 4900); (-1, 1) => (1600, 10200)
(2e3, 2e4, ps(2000), ps(100), 3, 1, um(400), 3e10),
// discr=4300: (-1, -1) => (-9600, 4200); (-1, 1) => (1300, 8500)
(5e3, 2e4, ps(2000), ps(100), 3, 1, um(400), 3e10),
// discr=3200: (-1, -1) => (-8700, 7000); (-1, 1) => (1700, 10200)
(5e3, 2e4, ps(2000), ps(100), 3, 1, um(400), 5e10),
] {
for &(init_flt_a, init_flt_b) in init_set {
@ -5756,6 +5867,134 @@ fn main() {
}
}
}
if true {
for init_set in [
// M1, M2 are treated as X and -X, respectively.
// because it's differential, testing (-1, 1) is sort of extraneous with (1, -1).
// generally only need to test the X > 0 region, if X == -X.
// but also test some cases where X != -X, due to error
&[
// establish rough domain/range
( 1.00, -1.00),
(-1.00, 1.00), // technically extraneous
( 0.00, 0.00),
( 0.20, -0.20),
( 0.10, -0.10),
(-1.00, -1.00), // uninitialized case
][..],
&[
// more detailed sweep
( 0.30, -0.30),
( 0.05, -0.05),
( 0.15, -0.15),
( 0.25, -0.25),
][..],
&[
// even more verbosity
( 0.02, -0.02),
( 0.07, -0.07),
( 0.12, -0.12),
( 0.17, -0.17),
( 0.22, -0.22),
][..],
&[
// negative side
(-0.10, 0.10),
(-0.20, 0.20),
(-0.25, 0.25),
(-0.05, 0.05),
(-0.15, 0.15),
(-0.02, 0.02),
(-0.07, 0.07),
(-0.12, 0.12),
(-0.17, 0.17),
(-0.22, 0.22),
][..],
&[
// test some asymmetries -- specifically where A1 is higher than expected
( 0.20, 0.00),
( 0.20, -0.10),
( 0.20, 0.10),
( 0.30, 0.00),
( 0.30, -0.20),
( 0.30, -0.10),
( 0.10, 0.00),
( 0.00, -0.10),
(-0.10, -0.30),
(-0.05, -0.20),
][..],
&[
// unexpected scenarios
(-0.20, -0.20),
(-0.10, -0.10),
( 0.10, 0.10),
][..],
] {
for (ctl_cond, coupling_cond, clock_duration, clock_decay, coupling_loops, inp_loops, s_major, cur_flt) in [
// total slot use is L*(4*A + 1),
// where L is the "coupling loops" and A is the inp_loops ("asymmetric loops")
// e.g. L=8, A=1 gives 40
// e.g. L=4, A=2 gives 36
// e.g. L=3, A=3 gives 39
// special case of A=0 is L*(2 + 1)
(2e3, 2e4, ps(2000), ps(100), 13, 0, um(400), 3e10),
// narrow region of >1 slope from x=0 to x=2700
(2e3, 2e4, ps(2000), ps(100), 8, 1, um(400), 3e10),
(2e3, 2e4, ps(2000), ps(100), 8, 1, um(400), 2e10),
(2e3, 2e4, ps(2000), ps(100), 4, 2, um(400), 3e10), // UNVERIFIED GEOM
] {
for &(init_flt_a, init_flt_b) in init_set {
// each core is coupled to 2 others + control slots
// M1 <-> M2 is symmetric (inputs)
// M1 -> M0 & M2 -> M3 are asymmetric (tx input -> output)
// M0 <-> M3 is symmetrics (outputs)
let slots_per_asym = (2*inp_loops).max(1);
let net_slots = 2*slots_per_asym + 1;
let mut params = params_v2
.with_clock_phase_duration(clock_duration)
.with_clock_decay(clock_decay)
.with_ctl_conductivity(ctl_cond)
.with_coupling_conductivity(coupling_cond)
.with_s_major(s_major)
.with_coupling_loops(coupling_loops)
.with_input_magnitude(cur_flt)
// control loops
.with_coupling(0, 0, 0, net_slots, CouplingMethod::Control)
.with_coupling(1, 1, 0, net_slots, CouplingMethod::Control)
.with_coupling(2, 2, 0, net_slots, CouplingMethod::Control)
.with_coupling(3, 3, 0, net_slots, CouplingMethod::Control)
;
for i in 0..slots_per_asym {
// couple output core 0 to core 3
params = params.with_coupling(0, 3, 1+i, net_slots, CouplingMethod::Outside);
// couple input core 1 to core 2
params = params.with_coupling(1, 2, 1+i, net_slots, CouplingMethod::Direct);
}
if inp_loops != 0 {
// couple input M1 -> output M0
params = couple_asymmetric_buffer_bi(&params, 0 /* low core */, 0, inp_loops, 1 + slots_per_asym /* slot offset */, net_slots);
// couple input M2 -> output M3
params = couple_asymmetric_buffer_bi(&params, 2 /* low core */, inp_loops, 0, 1 + slots_per_asym /* slot offset */, net_slots);
} else {
// directly couple M1->M0, M2->M3
params = params.with_coupling(0, 1, 1 + slots_per_asym, net_slots, CouplingMethod::Direct);
params = params.with_coupling(2, 3, 1 + slots_per_asym, net_slots, CouplingMethod::Direct);
}
let name = asymmetric_binary_gate_name(
&params, "53-buf-", coupling_loops /* ctl loops */, coupling_loops, 2*inp_loops + 1, init_flt_a, init_flt_b
);
run_sim(
&name,
drive_map_buf_53(init_flt_a, init_flt_b),
params,
);
}
}
}
}
}

View File

@ -18,6 +18,7 @@
natsort
pandas
plotly
scipy
];
python3 = pkgs.python3.withPackages python-packages;
in