A network-free simulate() with t_start above 0 labels its rows t_start…t_end on the bngsim backend but 0…(t_end − t_start) on BNG2.pl, so the same data are scored against different simulated times on the two backends and nothing warns

Aperta
#1,006 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
20/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
python
Ambito
data

Direzione di ricerca

Start with _nf_simulate_action in pybnf/bngsim_model/nf_model.py, where the bridge labels rows in absolute time, then the BNG2.pl path where pybnf/pset.py reads the .gdat as written, and _sim_row_for in pybnf/objective.py, which matches rows by time. Decide which clock is correct, then either refuse network-free simulate with t_start above 0 in the load-time checks in grid.py, or shift the BNG2.pl rows by t_start. Done means the reproduction in the issue gives the same objective on bngsim, bionetgen and auto.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

BngsimNfModel._nf_simulate_action (pybnf/bngsim_model/nf_model.py:427-499) reads t_start (nf_model.py:442) and calls sess.nfsim.simulate(t_start, t_end, n_steps + 1) (nf_model.py:498). The rows are labelled with absolute model time: t_start=>5,t_end=>10,n_steps=>5 gives rows at t = 5, 6, …, 10. BNG2.pl runs the same action through simulate_nf (BioNetGen 2.9.3, Perl2/BNGAction.pm:889-928). It starts NFsim with -sim (t_end - t_start), and NFsim writes its .gdat from 0, so the same action gives rows at t = 0, 1, …, 5. BNG2.pl knows this and prints WARNING: simulate_nf(): NFsim timepoints are reported as time elapsed since t_start=5. (BNGAction.pm:901-904). PyBNF writes that warning only to each simulation's BNG2.pl log, not to the console or to bnf_*.log.

Neither side translates between the two clocks:

  • PyBNF's BNG2.pl path reads the .gdat as written (pybnf/pset.py:1391-1392).
  • The objective pairs each data row with the simulation row that has the same time (_sim_row_for, pybnf/objective.py:591-629). The match is exact with ind_var_rounding = 0 (objective.py:613-616) and nearest-row with 1.
  • Nothing refuses the action at load. bng2pl_network_free_refusals (pybnf/bngsim_model/grid.py:274) and check_output_grids (grid.py:330) both accept it, and the classifier sends it to the bridge under the default bngl_backend = auto.

The data matching assumes that the simulator labels its rows on the data's own clock. Every other path labels with absolute model time:

  • BNG2.pl's own ODE simulate, which passes -i t_start to run_network (BNGAction.pm:480-481). The same action with method=>"ode" writes rows at 5…10.
  • The .net bridge.
  • Every action that edition 2 writes. These always say t_start=>0 (pset.py:1525).

So data written in absolute time are scored correctly on the bridge and against the wrong rows on BNG2.pl. Data copied from a BNG2.pl network-free .gdat are scored correctly on BNG2.pl and wrongly on the bridge. A fit can be right on only one backend. The documentation says the two backends write the same rows for every action except the sample_times case of #872 (docs/config_keys.rst:830-835; the module docstring of grid.py). That is not true for this action.

The mismatch is silent whenever the two label sets overlap, that is, when t_end − t_start ≥ t_start. A data time between t_start and t_end − t_start is then present in both outputs, so neither backend raises "not in the simulation output".

Failure scenario

An edition-1 network-free model records a time course from t = 5 to t = 15 (simulate({method=>"nf",t_start=>5,t_end=>15,n_steps=>10,...})). The data are at t = 5, 6, …, 10. On the default backend each datum is compared with the simulation at the same absolute time. On bngl_backend = bionetgen, the datum at t = 5 is compared with the state 5 time units after the start, which is absolute t = 10, and so on for every point. Both fits finish normally. At the same parameter values the objectives differ by a factor of more than 1000, and neither run prints a warning.

Reproduction

PyBNF v1.8.1 on main at dd4c6a3a, bngsim 0.16.0, BioNetGen 2.9.3.

The rows. nfdecay.bngl:

begin model
begin parameters
  A0 1000
  kdeg 0.1
end parameters
begin molecule types
  A()
end molecule types
begin seed species
  A() A0
end seed species
begin observables
  Molecules Atot A()
end observables
begin reaction rules
  A() -> 0 kdeg
end reaction rules
end model
begin actions
simulate({method=>"nf",t_start=>5,t_end=>10,n_steps=>5,suffix=>"tc",seed=>1})
end actions

perl $BNGPATH/BNG2.pl nfdecay.bngl writes nfdecay_tc.gdat with rows labelled 0, 1, 2, 3, 4, 5 (Atot 1000, 929, 847, 761, 687, 609). It also logs the "time elapsed since t_start=5" warning. The bngsim network-free bridge runs the same action, built as pybnf/algorithms/base.py:782-792 builds it, and labels its rows 5, 6, 7, 8, 9, 10 (Atot 1000, 895, 803, 733, 670, 609). With method=>"ode" plus generate_network, BNG2.pl labels its rows 5…10 as well.

The objective. The same model with kdeg kdeg__FREE in place of kdeg 0.1, and with the action

simulate({method=>"nf",t_start=>5,t_end=>15,n_steps=>10,suffix=>"tc"})

tc.exp is the exact decay measured in absolute time, 1000·exp(−0.1·(t − 5)):

# time Atot
5 1000.0
6 904.837
7 818.731
8 740.818
9 670.32
10 606.531

bngsim.conf (edition 1, so the job type defaults to de):

model = nfdecay.bngl : tc.exp
bngl_backend = bngsim
objfunc = sos
uniform_var = kdeg__FREE 0.0999 0.1001
population_size = 2
max_iterations = 1
random_seed = 1
parallel_count = 1
output_dir = out_bngsim
delete_old_files = 0

bionetgen.conf and auto.conf are the same with bngl_backend = bionetgen and bngl_backend = auto. Run pybnf -c on each. All three print Fitting complete and exit 0. The population is raised to 3, so each run has three evaluations at the same three values of kdeg (Results/sorted_params_final.txt):

kdeg__FREE bngsim and auto bionetgen
0.0999341 222.58 602497.21
0.1000300 490.10 550048.13
0.1000429 3379.17 631590.68

The best-fit .gdat explains the difference. On bngsim the rows run from 5 (Atot 1000) to 15 (347). On BNG2.pl the same trajectory is labelled 0 (1000) to 10 (374). So the datum at t = 5 (1000) is scored against Atot ≈ 615, the value 5 time units after the start. Network-free runs are stochastic, so the counts vary from run to run. The objective gap does not.

Siblings

  • A network-free parameter_scan with t_start above 0 is not affected. It records one row per scan point, keyed by the scanned value.
  • RuleMonkey (method=>"rm") and sample_times network-free actions exist only on the bridge, because BNG2.pl refuses them. They have no BNG2.pl rows to disagree with.
  • The .net bridge and BNG2.pl's ODE/SSA/PLA paths agree: both label rows in absolute time.
  • Not checked: a time-dependent rate law on the network-free path. BNG2.pl's NFsim starts its clock at 0, so time() there runs from 0, while the bridge's session may start its clock at t_start.

Possible fix

Decide which clock is right, and make the other backend agree or refuse:

  • refuse a network-free simulate with t_start other than 0 (with n_steps) at load, on both backends, naming the action. The user can then shift the data and write t_start=>0; or
  • shift BNG2.pl's network-free rows by t_start when PyBNF reads them, so that both backends use absolute time, as every other path does.

Either way, the "one difference remains" note in docs/config_keys.rst needs to list this case until it is fixed.

#1005

#1005 (fix/872-sample-times-grid, 44ef34e9) changes only sample_times grids. Rerunning the row reproduction against 44ef34e9 gives the same rows, 5…10, so this case is unchanged.

Related: #872 (the sample_times row difference), #999 (network-free actions BNG2.pl refuses).

Lingua principale
Python
Stelle
25
Fork
25
Merge medio
4h 5m
PR unite (30g)
10

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di lanl/PyBNF

Tutte le issue di lanl/PyBNF

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.