summaryrefslogtreecommitdiff
path: root/experiments/physical_bias_p1_smoke.py
diff options
context:
space:
mode:
Diffstat (limited to 'experiments/physical_bias_p1_smoke.py')
-rw-r--r--experiments/physical_bias_p1_smoke.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/experiments/physical_bias_p1_smoke.py b/experiments/physical_bias_p1_smoke.py
index dc9b6f1..c23c9eb 100644
--- a/experiments/physical_bias_p1_smoke.py
+++ b/experiments/physical_bias_p1_smoke.py
@@ -20,6 +20,8 @@ from sdil.physical_coupled import (
free_output,
joint_solution,
local_replay_update,
+ overclamped_clean_rate,
+ simulate_alternating_tasks,
standard_clean_rate,
)
@@ -73,12 +75,64 @@ def main() -> None:
downstream[:] = np.random.default_rng(29).normal(size=downstream.shape)
update_c = local_replay_update(affine, gates, teaching, eligibility, 0.03)
assert np.array_equal(update_a, update_c)
+
+ _, output_free, output_clamped = overclamped_clean_rate(
+ circuit,
+ joint,
+ tasks[0],
+ nudging=0.25,
+ clamp_magnitude=circuit.high,
+ exact_target=True,
+ )
+ expected_clamped = output_free + 0.25 * (
+ circuit.high * np.sign(tasks[0].label_voltage - output_free)
+ - output_free
+ )
+ assert output_clamped == expected_clamped
+
+ exact_predictor = LocalPredictor.zeros(
+ field.reference_gate, scale, affine=True)
+ exact_predictor.coefficients[:, 0] = field.bias_at_reference
+ exact_predictor.coefficients[:, 1] = field.local_slopes * scale
+ shared = {
+ "period_seconds": 0.01,
+ "cycles": 8,
+ "initial_gates": np.asarray((4.0, 4.0)),
+ "overclamp_nudging": 0.25,
+ "overclamp_magnitude": circuit.high,
+ "overclamp_exact_target": True,
+ }
+ clean_overclamp = simulate_alternating_tasks(
+ circuit,
+ tasks,
+ field,
+ method="overclamp",
+ bias_strength=0.0,
+ **shared,
+ )
+ debiased_overclamp = simulate_alternating_tasks(
+ circuit,
+ tasks,
+ field,
+ method="overclamp_sdil",
+ bias_strength=1.0,
+ predictor=exact_predictor,
+ **shared,
+ )
+ assert np.allclose(
+ clean_overclamp["final_gates"],
+ debiased_overclamp["final_gates"],
+ atol=1e-12,
+ rtol=0.0,
+ )
+ assert debiased_overclamp["max_abs_clamp_displacement_v"] > 0.0
print({
"joint_solution": joint.tolist(),
"affine_calibration_mae": float(affine_error),
"constant_calibration_mae": float(constant_error),
"neutral_observations_each": observations_affine,
"local_replay_exact": True,
+ "sdil_overclamp_composition_exact": True,
"autodiff_used": False,
})