app: stacked_cores: 53-xx: better constrain the interpolation, and plot slope
This commit is contained in:
parent
373c80793f
commit
3ebcc550a0
|
@ -16,4 +16,5 @@ 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(f"{name}", "a0", trace)
|
||||
plot(name, "a0", trace)
|
||||
plot_slope(f"slope {name}", "a0", trace)
|
||||
|
|
|
@ -13,6 +13,15 @@ def plot(name: str, x_name: str, y_series: list):
|
|||
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`.
|
||||
|
@ -35,7 +44,7 @@ def sample_all(meas: 'ParameterizedMeas', at: tuple, extract_tx) -> tuple:
|
|||
effectively fillin in whichever items in `at` are left at `None`
|
||||
"""
|
||||
runs = [extract_tx(r) for r in meas.runs()]
|
||||
distances = [(distance_to(m, at), m) for m in 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)
|
||||
|
@ -63,6 +72,7 @@ def interpolate_minl1(at: tuple, runs: list, distances: list) -> tuple:
|
|||
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):
|
||||
|
@ -70,6 +80,9 @@ def interpolate_minl1(at: tuple, runs: list, distances: list) -> tuple:
|
|||
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)
|
||||
|
||||
|
@ -79,7 +92,8 @@ def interpolate_minl1(at: tuple, runs: list, distances: list) -> tuple:
|
|||
|
||||
# compute the weight of each run
|
||||
init = [0]*num_runs
|
||||
res = opt.minimize(score, init, method='trust-constr', constraints=[eq_constraint], bounds=bounds)
|
||||
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
|
||||
|
@ -133,7 +147,10 @@ def distance_to(p0: tuple, p1: tuple) -> float:
|
|||
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(sum((x0-x1)*(x0-x1) for (x0, x1) in zip(p0, p1) if x0 is not None and x1 is not None))
|
||||
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:
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue