run_diffrax steps over a narrow Gaussian pulse of the clock: X(100) = 0 for 100 at every rtol, in 7 steps, with no warning (it places none of the #1286 smooth-pulse stops Simulator.run uses)
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 84/100
Research direction
Read python/bngsim/_diffrax_solver.py around _switch_times (lines 384–452) and compare it with how Simulator.run uses smooth_pulse_stops in _simulator.py around lines 2445–2452. First inspect python/bngsim/_smooth_pulses.py around line 181 to see how pulse stop times are produced. Done means run_diffrax includes those stops and the supplied reproduction returns X(100) close to 100.
Written by the indexing model from the issue text.
Description
run_diffrax steps right over a narrow Gaussian pulse of the clock. The model makes X at kx/(s*sqrt(pi))*exp(-((time()-c)/s)^2), a pulse of area kx = 100 centred at t = 50, so X(100) = 100 exactly.
Simulator.run: 100.00003. It has placed smooth-pulse stops since #1286.run_diffrax: 0.0, in 7 steps, at rtol 1e-6, 1e-8 and 1e-10, for pulse widths s = 0.05 and s = 0.5. No warning.
Found by checking a lead of #1532 (sibling of #902). Reproduced on main 5d7a5318 (editable build, macOS arm64, Python 3.13), with jax 0.9.0.1 and diffrax 0.7.2.
Repro
"""run_diffrax and a narrow Gaussian pulse of the clock. Needs the jax extra (jax, diffrax).
0 -> X at kx/(s*sqrt(pi))*exp(-((time()-c)/s)^2): the pulse's area is kx, so X(100) = kx = 100 exactly."""
import contextlib, io, os, tempfile, warnings
import numpy as np
import bngsim
from bngsim._diffrax_solver import run_diffrax
NET = """begin parameters
1 kx 100
2 c 50
3 s {s!r}
end parameters
begin functions
1 f() kx/(s*sqrt(_pi))*exp(-((time()-c)/s)^2)
end functions
begin species
1 X() 0
end species
begin reactions
1 0 1 f #_FUNC
end reactions
begin groups
1 Xobs 1
end groups
"""
def model(s):
p = os.path.join(tempfile.mkdtemp(), "m.net")
with open(p, "w") as fh:
fh.write(NET.format(s=s))
with contextlib.redirect_stderr(io.StringIO()):
return bngsim.Model.from_net(p)
for s in (0.05, 0.5):
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
r = bngsim.Simulator(model(s), method="ode").run(t_span=(0, 100), n_points=3)
print(f"s={s}: Simulator.run X(100) = {float(np.asarray(r.species)[-1, 0]):.6f}")
for rtol in (1e-6, 1e-8, 1e-10):
d = run_diffrax(model(s), t_start=0.0, t_end=100.0, n_points=3, rtol=rtol, atol=rtol)
print(f" run_diffrax rtol={rtol:g}: X(100) = {float(np.asarray(d['species'])[-1, 0]):.6f} n_steps={d['n_steps']}")
print(f" exact 100; warnings={len(w)}")
Output
s=0.05: Simulator.run X(100) = 100.000027
run_diffrax rtol=1e-06: X(100) = 0.000000 n_steps=7
run_diffrax rtol=1e-08: X(100) = 0.000000 n_steps=7
run_diffrax rtol=1e-10: X(100) = 0.000000 n_steps=7
exact 100; warnings=0
s=0.5: Simulator.run X(100) = 100.000018
run_diffrax rtol=1e-06: X(100) = 0.000000 n_steps=7
run_diffrax rtol=1e-08: X(100) = 0.000000 n_steps=7
run_diffrax rtol=1e-10: X(100) = 0.000000 n_steps=7
exact 100; warnings=0
Where
_switch_times (python/bngsim/_diffrax_solver.py:384-452) places stops only from time_discontinuity_conditions() through crossings_with_periodic. It never calls smooth_pulse_stops (python/bngsim/_smooth_pulses.py:181), which Simulator.run calls (_simulator.py ~2445-2452). A Gaussian has no condition, so the diffrax path gets no stop at all.
Fix direction: add the smooth_pulse_stops times to the diffrax stop set the same way Simulator.run does.
- Dominant language
- Python
- Stars
- 3
- Forks
- 6
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 295
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from lanl/bngsim
-
testing
Difficulty 1/5 Under an hour Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
bug latent bug low priority
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
Maintainers usually reply within 1 day
-
benchmarks/README: 'perl BNG2.pl model.bngl' runs the whole protocol, not just generate_networkOpendocumentation
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 22/100
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
software-mansion-labs/Diplomat#20 ·
Maintainers usually reply within 1 day
-
[Windows] Hidden title bar: a maximized window restored from minimized on a secondary monitor gets the primary monitor's work area as its client areaPossibly taken @lijy91 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
libnativeapi/nativeapi#53 · 1 reaction ·
Maintainers usually reply within 1 day
-
View Counts discarded due to field name mismatchPossibly taken @rsiva0400 claimed this today. Opensite-bug triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Model version publishes the new UK firm entity as a personPossibly taken @vahid-ahmadi claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
PolicyEngine/policyengine.py#764 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
spcl/HPCAgent-Bench#264 ·
Maintainers usually reply within 1 day