The .net loader reads a parameter named inf, nan or Infinity, used as a whole value, as that number

Open
#1,856 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
62/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
cpp, python
Domain
backend

Research direction

Start in src/net_file_loader.cpp at the parameter-value read (around line 290) and the species-concentration read (around line 411), where c_stod runs before the name lookup. Compare them with the statistical-factor reader for nan*kf (issue #803), which already rejects non-finite values. Done when a test loads the five names (inf, nan, Infinity, true, q) through BNG2.pl and matches its B(0), k2 and k3 values.

Written by the indexing model from the issue text.

Description

What happens

BNG2.pl accepts a parameter named inf, nan or Infinity. When a parameter's whole value, or a seed species' whole concentration, is that one name, BNG2.pl writes the name into the .net file as it is (k2 inf, 2 B() inf). Model.from_net reads the name as the number: infinity, or NaN. BNG2.pl reads it as the parameter. Nothing warns at load, and a finite value computed from it is wrong with no error (below).

Checked on main ba094bb3 (bngsim 0.17.2), with BNG2.pl 2.9.3:

begin parameters
  inf 5
  k2  inf
  k3  2*inf
end parameters
begin seed species
  A() 100
  B() inf
end seed species
name BNG2.pl: B(0) from_net: B(0) from_net: k2 from_net: k3
inf 5 inf inf 10
nan 5 nan nan 10
Infinity 5 inf inf 10
true 5 5 5 10
q 5 5 5 10

k3 2*inf is right because it is an expression. Only a value that is the name alone is read as a number.

Why

src/net_file_loader.cpp reads a parameter's value (line 290) and a species' concentration (line 411) with c_stod first, and treats the text as a name or an expression only when that fails or leaves text over. c_stod, like strtod, accepts inf, infinity and nan in any case, so those names never reach the name lookup.

Two other readers in the same file already refuse a non-finite number: a rate's statistical factor (nan*kf, issue #803) and an observable group entry's factor. These two sites have no such check.

Reach

  • Model.from_net on a .net file that BNG2.pl wrote, and Model.from_bngl, which loads BNG2.pl's .net (from_bngl on the model above: B(0) = inf, k2 = inf).
  • A seed species or a rate constant that is such a parameter alone is inf or NaN. An ODE run refuses it, but the message names a non-finite initial condition, not the name.
  • A finite value computed from such a parameter is wrong, and nothing is said. With k2 inf and k4 1/k2, bngsim reads k4 = 0. For A() -> B() k4 from A = 100, an ODE run to t = 1 gives B(1) = 0, where BNG2.pl gives 18.1269 (the same for Infinity; for nan the run raises).

A possible fix

At both sites, read a value that is a declared parameter's name as that parameter, before trying it as a number. Alternatively, accept only a finite number there, and read anything else as a name, as the statistical-factor reader does. Either way, a test should load the table's five names through BNG2.pl and compare B(0), k2 and k3 with BNG2.pl's values.

Dominant language
Python
Stars
3
Forks
6
Avg merge
1d 1h
Merged PRs (30d)
295

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from lanl/bngsim

All issues in lanl/bngsim

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.