ProtocolSpec.to_json and write_sedml_protocol raise TypeError on a numpy integer that run_protocol accepts: a seed of np.int64(42), as rng.integers() gives, cannot be written
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- json, numpy, python
- Domain
- data-engineering
Research direction
The failure is in python/bngsim/convert/_protocol.py: ProtocolSpec.to_json calls json.dumps(self.to_dict()) and Experiment.to_dict copies fields and extra unchanged. Run the repro script to see the TypeError on the np.int64 seed, then either convert numpy integers in to_dict or pass a default= to json.dumps that maps np.integer to int. Done when write_sedml_protocol writes a protocol with a numpy seed, n_points or scan_points, and the output matches the int case.
Written by the indexing model from the issue text.
Description
A ProtocolSpec whose experiment holds a numpy integer runs with run_protocol but cannot be written. A seed from rng.integers() is the usual way to get one. ProtocolSpec.to_json() hands the value to json.dumps as is, which raises TypeError: Object of type int64 is not JSON serializable, and so does write_sedml_protocol, which embeds that JSON in its annotation. A numpy n_points or scan_points fails the same way. EvaluationSpec.to_json() writes the same numpy seed without complaint.
Repro (uv run --no-sync python repro.py)
"""A numpy integer in a ProtocolSpec runs, but the protocol cannot be written."""
import os
import tempfile
import warnings
import numpy as np
import bngsim
from bngsim.convert import Experiment, ProtocolSpec, write_sedml_protocol
net = """begin parameters
1 kp 200.0
2 kd 0.5
end parameters
begin species
1 A() 0
end species
begin reactions
1 0 1 kp
2 1 0 kd
end reactions
"""
d = tempfile.mkdtemp()
path = os.path.join(d, "m.net")
open(path, "w").write(net)
model = bngsim.Model.from_net(path)
warnings.simplefilter("ignore") # the no-SBML-target warning is beside the point here
for seed in (42, np.int64(42)):
exp = Experiment(kind="simulate", method="ssa", t_span=(0.0, 10.0), n_points=11, extra={"seed": seed})
spec = ProtocolSpec(steps=(exp,), source=None)
bngsim.run_protocol(model, spec) # runs either way
try:
write_sedml_protocol(spec, os.path.join(d, "p.sedml"), model=model)
print(f"{type(seed).__name__} seed: written")
except TypeError as e:
print(f"{type(seed).__name__} seed: TypeError: {e}")
Output on main 07ff9f69:
int seed: written
int64 seed: TypeError: Object of type int64 is not JSON serializable
spec.to_json() raises the same TypeError for n_points=np.int64(11), and for scan_points=np.int64(3) on a scan.
Expected: a protocol that runs can be written, with numpy integers serialized as the integers they are, as EvaluationSpec does for its seed.
Observed: TypeError from json.dumps, so the protocol can be run but not saved.
Where
python/bngsim/convert/_protocol.py: ProtocolSpec.to_json (json.dumps(self.to_dict())) and Experiment.to_dict, which copies its fields and extra as given. Converting numpy integers in to_dict, or a default= on json.dumps that turns np.integer into int, would cover every field.
Found while reviewing #1641's seed handling, which accepts numpy seeds for runs. Duplicate check: no issue covers it. #1517 (closed) was EvaluationSpec's missing seed, and #1677, #1686 and #1734, all closed, were other SED-ML writer defects.
- Dominant language
- Python
- Stars
- 3
- Forks
- 5
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 361
Getting set up
- No Dockerfile or Docker Compose file
- No 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
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/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 1/5 1-3 hours Newbie friendliness 91/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
Similar issues
-
ライブラリを追加Openpriority middle
Difficulty 1/5 Under an hour Newbie friendliness 62/100
KATO-Hiro/AtCoderClans#13015 ·
Maintainers usually reply within 1 day
-
StringLiteral to IntegerType/LongType silently truncates fractional strings, changing predicate meaningPossibly taken @Shahzeb-DataEngineer claimed this today. Openkind:bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
apache/iceberg-python#4382 · 2 comments ·
Maintainers usually reply within 1 day
-
request-theme
Difficulty 2/5 Under an hour Newbie friendliness 62/100
LizardByte/ThemerrDB#10024 · 2 comments ·
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
btclib-org/btclib-node#2505 · 1 comment ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
open-webui/open-webui#34462 · 1 comment ·
Maintainers usually reply within 1 day