Sensor accepts a SeedSequence seed but cannot serialize it
Maintainer antworten meist innerhalb von 3 Tagen
@myungjunlee arbeitet bereits daran.
Seit 07.8.2026.
Bewertung
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Anfängerfreundlichkeit
- 22/100
Rechercherichtung
The constructor and to_dict live on the sensor (see Accelerometer and Sensor.__init__ keeping self._seed); serialization fails in rocketpy._encoders.RocketPyEncoder when the seed is a numpy.random.SeedSequence. Reproduce with the snippet in the issue. Maintainers already merged PRs 1124 and 1174 against this area, so read those first and do not start a new design until it is clear the remaining gap is still open. Done means either a documented round-trip of SeedSequence.state or a constructor TypeError for non-JSON seeds, with tests covering both paths.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Summary
Sensor.__init__ accepts anything numpy.random.default_rng accepts, keeps it, and hands it straight back from to_dict():
self._seed = seed
self._rng = np.random.default_rng(seed)
...
"seed": self._seed,
default_rng accepts a SeedSequence, so constructing a sensor with one succeeds. RocketPyEncoder has no case for SeedSequence, so serializing that sensor raises TypeError, and it raises at whatever point the object graph is written out rather than where the value came in.
Reproduction
import json
import numpy as np
from rocketpy.sensors import Accelerometer
from rocketpy._encoders import RocketPyEncoder
seed = np.random.SeedSequence(0).spawn(1)[0]
sensor = Accelerometer(sampling_rate=100, seed=seed) # accepted
json.dumps(sensor.to_dict(), cls=RocketPyEncoder) # TypeError
Why it is worth closing
Spawning a SeedSequence per component is the idiom NumPy documents for decorrelating sub-streams, so it is a natural thing to reach for when seeding several sensors from one run seed. It works right up until something serializes the flight.
We hit exactly that downstream: a simulation seeded its three sensors from spawned children, every run worked, and packing the result to JSON failed for every user. The fix there was to convert each child to an int before it reaches the sensor, which works but throws away the child's spawn_key, so the resulting stream is not the one the child would have produced.
Two ways to close it
Accept it. Document the seed type as int | Sequence[int] | SeedSequence | None, serialize a tagged form of SeedSequence.state, and rebuild with SeedSequence(**state) on load. That also lets a caller keep the child's exact stream through a round trip, which converting to an int cannot.
Reject it. Validate in the constructor that the seed is JSON representable and raise a clear TypeError naming the type. Narrow the docstring and type hints to match.
Either is fine. What is worth avoiding is the current state, where construction succeeds and the failure surfaces much later in an unrelated call.
A related note on width
If the tagged-state route is taken, it also sidesteps a second problem. Converting a child to a full-width int gives a 128-bit value, which is exact in Python but larger than a JavaScript Number can represent. A submission we produce carries three such integers, and any consumer parsing that JSON with IEEE-754 doubles would round them.
Happy to send a PR for whichever direction you prefer.
- Vorherrschende Sprache
- Python
- Sterne
- 1.1k
- Forks
- 280
- Ø Merge
- 3 T. 2 Std.
- Gemergte PRs (30 T.)
- 24
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus RocketPy-Team/RocketPy
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
RocketPy-Team/RocketPy#1255 ·
Maintainer antworten meist innerhalb von 3 Tagen
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 92/100
RocketPy-Team/RocketPy#1241 ·
Maintainer antworten meist innerhalb von 3 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
RocketPy-Team/RocketPy#1202 ·
Maintainer antworten meist innerhalb von 3 Tagen
-
Monte Carlo test fixtures write their logs into the working directoryEvtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
RocketPy-Team/RocketPy#1189 ·
Maintainer antworten meist innerhalb von 3 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
RocketPy-Team/RocketPy#1171 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 3 Tagen
Alle Issues in RocketPy-Team/RocketPy
Ähnliche Issues
-
docs(contributing): the two things that silently block a PREvtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offenavailable documentation good first issue
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 95/100
Nixitov/Riptide-Native#944 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
JTHCode/secretguard#24 ·
Maintainer antworten meist innerhalb von 1 Tag
-
area: middleware documentation good first issue
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
-
enhancement good first issue
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
Maintainer antworten meist innerhalb von 1 Tag
-
good first issue
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 95/100
omarelshamy25x/shamy-hijri#63 ·
Maintainer antworten meist innerhalb von 1 Tag