Skip to content

Commit b961e7b

Browse files
committed
Add detection threshold UQ demo script and corresponding test
1 parent d1723a5 commit b961e7b

3 files changed

Lines changed: 65 additions & 38 deletions

File tree

.github/workflows/ci.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,8 @@ jobs:
9191
- name: Run local energy resolution UQ demo
9292
run: |
9393
cd negative-energy-generator
94-
python scripts/local_energy_resolution_uq.py --alpha 1.0 --beta 1.0 --N 50 100 200 --L 10.0 --output results/local_energy_resolution_uq.json
94+
python scripts/local_energy_resolution_uq.py --alpha 1.0 --beta 1.0 --N 50 100 200 --L 10.0 --output results/local_energy_resolution_uq.json
95+
- name: Run detection threshold UQ demo
96+
run: |
97+
cd negative-energy-generator
98+
python scripts/detection_threshold_uq.py --alpha 1.0 --beta 1.0 --thresholds -1.0 0.0 1.0 --N 50 --L 10.0 --output results/detection_threshold_uq.json

docs/progress_log.md

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@
1414
```file-history
1515
~/Code/asciimath/negative-energy-generator$ find . -path "./.venv" -prune -o -type f -regex '.*\.\(ps1\|py\|sh\|ndjson\|json\|md\|yml\|toml\|h5\|ini\)$' -print | while read file; do stat -c '%Y %n' "$file"; done | sort -nr | while read timestamp file; do echo "$(date -d @$timestamp '+%Y-%m-%d %H:%M:%S') $file"; done | head -n 40
1616
# LATEST-FILES-LIST-BEGIN
17+
2025-08-03 22:31:32 ./tests/test_detection_threshold_uq.py
18+
2025-08-03 22:31:32 ./.github/workflows/ci.yml
19+
2025-08-03 22:30:24 ./docs/progress_log.md
20+
2025-08-03 22:30:20 ./results/dynamic_evolution_metrics.json
21+
2025-08-03 22:30:19 ./results/dynamic_evolution.h5
1722
2025-08-03 22:30:00 ./scripts/detection_threshold_uq.py
18-
2025-08-03 22:26:35 ./docs/progress_log.md
19-
2025-08-03 22:26:31 ./results/dynamic_evolution_metrics.json
20-
2025-08-03 22:26:30 ./results/dynamic_evolution.h5
2123
2025-08-03 22:26:19 ./tests/test_local_energy_resolution_uq.py
2224
2025-08-03 22:26:19 ./scripts/local_energy_resolution_uq.py
23-
2025-08-03 22:26:19 ./.github/workflows/ci.yml
2425
2025-08-03 22:21:52 ./src/simulation/qft_backend.py
2526
2025-08-03 22:14:25 ./tests/test_dark_fluid_demo.py
2627
2025-08-03 22:14:25 ./tests/test_dark_fluid.py
@@ -53,7 +54,6 @@
5354
2025-08-03 13:26:05 ./docs/technical-documentation.md
5455
2025-08-03 13:26:05 ./UQ-TODO.ndjson
5556
2025-08-03 12:46:57 ./tests/test_dynamic_evolution_export.py
56-
2025-08-03 12:46:57 ./pytest.ini
5757
# LATEST-FILES-LIST-END
5858
5959
~/Code/asciimath/negative-energy-generator$ ls .. -lt | awk '{print $1, $2, $5, $6, $7, $8, $9}'
@@ -125,64 +125,65 @@ cachedir: .pytest_cache
125125
rootdir: /home/echo_/Code/asciimath/negative-energy-generator
126126
configfile: pytest.ini
127127
testpaths: tests
128-
collecting ... collected 54 items
128+
collecting ... collected 55 items
129129
130130
tests/test_analytical_solution.py::test_analytical_solution_massless PASSED [ 1%]
131131
tests/test_backreaction.py::test_solve_semiclassical_metric_shapes_and_initial_step PASSED [ 3%]
132132
tests/test_backreaction_export.py::test_backreaction_demo_export PASSED [ 5%]
133133
tests/test_backreaction_stability.py::test_constant_source_growth_matches_theoretical PASSED [ 7%]
134134
tests/test_backreaction_uq.py::test_backreaction_uq_script PASSED [ 9%]
135-
tests/test_backreaction_uq_report.py::test_backreaction_uq_report_script PASSED [ 11%]
135+
tests/test_backreaction_uq_report.py::test_backreaction_uq_report_script PASSED [ 10%]
136136
tests/test_backreaction_wave.py::test_zero_source_remains_zero PASSED [ 12%]
137137
tests/test_dark_fluid.py::test_generate_negative_mass_fluid_defaults PASSED [ 14%]
138138
tests/test_dark_fluid.py::test_anec_negative_fluid PASSED [ 16%]
139139
tests/test_dark_fluid_demo.py::test_dark_fluid_demo_script PASSED [ 18%]
140-
tests/test_diagnostics.py::TestInterferometricProbe::test_frequency_response PASSED [ 20%]
141-
tests/test_diagnostics.py::TestInterferometricProbe::test_initialization PASSED [ 22%]
142-
tests/test_diagnostics.py::TestInterferometricProbe::test_phase_shift_calculation PASSED [ 24%]
143-
tests/test_diagnostics.py::TestInterferometricProbe::test_phase_shift_scaling PASSED [ 25%]
144-
tests/test_diagnostics.py::TestInterferometricProbe::test_simulate_pulse PASSED [ 27%]
145-
tests/test_diagnostics.py::TestCalorimetricSensor::test_initialization PASSED [ 29%]
146-
tests/test_diagnostics.py::TestCalorimetricSensor::test_simulate_pulse PASSED [ 31%]
147-
tests/test_diagnostics.py::TestCalorimetricSensor::test_temp_rise_calculation PASSED [ 33%]
148-
tests/test_diagnostics.py::TestPhaseShiftInterferometer::test_acquire PASSED [ 35%]
149-
tests/test_diagnostics.py::TestPhaseShiftInterferometer::test_frequency_sweep PASSED [ 37%]
150-
tests/test_diagnostics.py::TestPhaseShiftInterferometer::test_initialization PASSED [ 38%]
151-
tests/test_diagnostics.py::TestRealTimeDAQ::test_add_sample PASSED [ 40%]
152-
tests/test_diagnostics.py::TestRealTimeDAQ::test_circular_buffer PASSED [ 42%]
153-
tests/test_diagnostics.py::TestRealTimeDAQ::test_initialization PASSED [ 44%]
154-
tests/test_diagnostics.py::TestRealTimeDAQ::test_reset PASSED [ 46%]
155-
tests/test_diagnostics.py::TestRealTimeDAQ::test_statistics PASSED [ 48%]
140+
tests/test_detection_threshold_uq.py::test_detection_threshold_uq PASSED [ 20%]
141+
tests/test_diagnostics.py::TestInterferometricProbe::test_frequency_response PASSED [ 21%]
142+
tests/test_diagnostics.py::TestInterferometricProbe::test_initialization PASSED [ 23%]
143+
tests/test_diagnostics.py::TestInterferometricProbe::test_phase_shift_calculation PASSED [ 25%]
144+
tests/test_diagnostics.py::TestInterferometricProbe::test_phase_shift_scaling PASSED [ 27%]
145+
tests/test_diagnostics.py::TestInterferometricProbe::test_simulate_pulse PASSED [ 29%]
146+
tests/test_diagnostics.py::TestCalorimetricSensor::test_initialization PASSED [ 30%]
147+
tests/test_diagnostics.py::TestCalorimetricSensor::test_simulate_pulse PASSED [ 32%]
148+
tests/test_diagnostics.py::TestCalorimetricSensor::test_temp_rise_calculation PASSED [ 34%]
149+
tests/test_diagnostics.py::TestPhaseShiftInterferometer::test_acquire PASSED [ 36%]
150+
tests/test_diagnostics.py::TestPhaseShiftInterferometer::test_frequency_sweep PASSED [ 38%]
151+
tests/test_diagnostics.py::TestPhaseShiftInterferometer::test_initialization PASSED [ 40%]
152+
tests/test_diagnostics.py::TestRealTimeDAQ::test_add_sample PASSED [ 41%]
153+
tests/test_diagnostics.py::TestRealTimeDAQ::test_circular_buffer PASSED [ 43%]
154+
tests/test_diagnostics.py::TestRealTimeDAQ::test_initialization PASSED [ 45%]
155+
tests/test_diagnostics.py::TestRealTimeDAQ::test_reset PASSED [ 47%]
156+
tests/test_diagnostics.py::TestRealTimeDAQ::test_statistics PASSED [ 49%]
156157
tests/test_diagnostics.py::TestRealTimeDAQ::test_trigger_modes PASSED [ 50%]
157-
tests/test_diagnostics.py::TestUtilityFunctions::test_benchmark_instrumentation_suite PASSED [ 51%]
158-
tests/test_diagnostics.py::TestUtilityFunctions::test_generate_T00_pulse PASSED [ 53%]
159-
tests/test_diagnostics.py::TestIntegration::test_complete_measurement_chain PASSED [ 55%]
160-
tests/test_diagnostics.py::TestIntegration::test_multi_sensor_comparison PASSED [ 57%]
161-
tests/test_dynamic_evolution.py::test_dynamic_energy_conservation PASSED [ 59%]
158+
tests/test_diagnostics.py::TestUtilityFunctions::test_benchmark_instrumentation_suite PASSED [ 52%]
159+
tests/test_diagnostics.py::TestUtilityFunctions::test_generate_T00_pulse PASSED [ 54%]
160+
tests/test_diagnostics.py::TestIntegration::test_complete_measurement_chain PASSED [ 56%]
161+
tests/test_diagnostics.py::TestIntegration::test_multi_sensor_comparison PASSED [ 58%]
162+
tests/test_dynamic_evolution.py::test_dynamic_energy_conservation PASSED [ 60%]
162163
tests/test_dynamic_evolution_accuracy.py::test_dynamic_evolution_energy_drift PASSED [ 61%]
163-
tests/test_dynamic_evolution_analysis.py::test_dynamic_evolution_analysis PASSED [ 62%]
164-
tests/test_dynamic_evolution_discretization.py::test_dynamic_evolution_discretization_accuracy PASSED [ 64%]
165-
tests/test_dynamic_evolution_export.py::test_dynamic_evolution_demo_export PASSED [ 66%]
166-
tests/test_dynamic_evolution_plot.py::test_dynamic_evolution_plot PASSED [ 68%]
164+
tests/test_dynamic_evolution_analysis.py::test_dynamic_evolution_analysis PASSED [ 63%]
165+
tests/test_dynamic_evolution_discretization.py::test_dynamic_evolution_discretization_accuracy PASSED [ 65%]
166+
tests/test_dynamic_evolution_export.py::test_dynamic_evolution_demo_export PASSED [ 67%]
167+
tests/test_dynamic_evolution_plot.py::test_dynamic_evolution_plot PASSED [ 69%]
167168
tests/test_dynamic_evolution_report.py::test_dynamic_evolution_report PASSED [ 70%]
168169
tests/test_energy_conservation.py::test_energy_conservation PASSED [ 72%]
169170
tests/test_evolve_qft.py::test_evolve_qft_fallback_identity PASSED [ 74%]
170-
tests/test_lattice_discretization.py::test_laplacian_accuracy_for_sine_wave PASSED [ 75%]
171-
tests/test_lattice_energy.py::test_compute_energy_density_zero_field PASSED [ 77%]
172-
tests/test_lattice_energy.py::test_solve_klein_gordon_basic PASSED [ 79%]
171+
tests/test_lattice_discretization.py::test_laplacian_accuracy_for_sine_wave PASSED [ 76%]
172+
tests/test_lattice_energy.py::test_compute_energy_density_zero_field PASSED [ 78%]
173+
tests/test_lattice_energy.py::test_solve_klein_gordon_basic PASSED [ 80%]
173174
tests/test_lattice_sweep_demo.py::test_lattice_sweep_demo PASSED [ 81%]
174175
tests/test_local_energy_resolution_uq.py::test_local_energy_resolution_uq PASSED [ 83%]
175176
tests/test_parameter_sweep_export.py::test_parameter_sweep_export PASSED [ 85%]
176177
tests/test_qft_backend.py::test_qft_backend_smoke PASSED [ 87%]
177-
tests/test_qft_backend_anec.py::test_compute_anec_and_check_anec_positive PASSED [ 88%]
178+
tests/test_qft_backend_anec.py::test_compute_anec_and_check_anec_positive PASSED [ 89%]
178179
tests/test_qft_backend_anec.py::test_compute_anec_and_check_anec_negative PASSED [ 90%]
179180
tests/test_qft_backend_vnv.py::test_build_toy_ansatz_shape_and_values PASSED [ 92%]
180181
tests/test_qft_backend_vnv.py::test_local_energy_density_and_find_negative PASSED [ 94%]
181182
tests/test_qft_toy_ansatz_uq.py::test_qft_toy_ansatz_uq_script PASSED [ 96%]
182183
tests/test_time_integration_basic.py::test_solve_klein_gordon_shapes_and_values PASSED [ 98%]
183184
tests/test_zero_initial_condition.py::test_zero_initial_condition PASSED [100%]
184185
185-
============================== 54 passed in 9.76s ==============================
186+
============================= 55 passed in 10.34s ==============================
186187
# PYTEST-RESULTS-END
187188
# Never skip a test if an import isn't available. Those tests should fail and the import should be fixed.
188189
~/Code/asciimath$ grep -r "importerskip" --include="*.py" . | wc -l
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import json
2+
import subprocess
3+
import sys
4+
5+
def test_detection_threshold_uq(tmp_path):
6+
output = tmp_path / "threshold_uq.json"
7+
# Run the CLI tool with two thresholds
8+
cmd = [sys.executable, "scripts/detection_threshold_uq.py",
9+
"--alpha", "1.0", "--beta", "1.0",
10+
"--thresholds", "-0.5", "0.0", "0.5",
11+
"--N", "20", "--L", "4.0",
12+
"--output", str(output)]
13+
subprocess.check_call(cmd)
14+
data = json.loads(output.read_text())
15+
# Validate structure
16+
assert data["alpha"] == 1.0
17+
assert data["beta"] == 1.0
18+
assert data["thresholds"] == [-0.5, 0.0, 0.5]
19+
assert "fractions" in data and len(data["fractions"]) == 3
20+
# Fractions should be between 0 and 1
21+
for frac in data["fractions"]:
22+
assert 0.0 <= frac <= 1.0

0 commit comments

Comments
 (0)