import numpy as np
rng = np.random.default_rng(seed=42)
print(rng.normal(size=3))
rng = np.random.default_rng(seed=42)
print(rng.normal(size=3)) # identical[ 0.30471708 -1.03998411 0.7504512 ]
[ 0.30471708 -1.03998411 0.7504512 ]
Module 1: Low-Dimensional Dynamics
A result is reproducible when someone else can run your code and obtain the same numbers and figures. You will need this for the assignments and the group project. The practices below follow (sandve2013ten?).
Record the exact package versions you used. The course repository does this in requirements.txt:
matplotlib==3.10.8
numpy==2.2.5
scipy==1.14.1
streamlit==1.53.0
Create a clean environment and install from the file:
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txtAfter adding a package, write the versions back with pip freeze > requirements.txt and remove the lines you do not need.
Any simulation with randomness must set a seed, and the seed must appear in the code, not only in your notes. Use a local generator instead of the global state:
import numpy as np
rng = np.random.default_rng(seed=42)
print(rng.normal(size=3))
rng = np.random.default_rng(seed=42)
print(rng.normal(size=3)) # identical[ 0.30471708 -1.03998411 0.7504512 ]
[ 0.30471708 -1.03998411 0.7504512 ]
Deterministic ODE solvers such as solve_ivp give the same output for the same input, but results still depend on rtol, atol and method. Write these values explicitly in your code.
C:\Users\....data/ with a README.md.A classmate sends you analysis.py that reads C:/Users/ana/Desktop/cases.csv, uses np.random.rand without a seed, and imports streamlit which is not in requirements.txt. List the three changes needed to make it reproducible.
data/cases.csv) and read it with a relative path.rng = np.random.default_rng(seed) and use rng.random instead of np.random.rand.streamlit with its version to requirements.txt.Session 4 returns to the budworm with the code from this session.
You run the same budworm simulation twice with solve_ivp and get identical numbers, but a classmate with a different SciPy version gets values that differ in the fourth decimal. Is your result reproducible?
Your result is repeatable on your machine but not fully reproducible. Different library versions can change default settings or internal algorithms. Pin the version in requirements.txt and set rtol and atol explicitly. Differences below the solver tolerance do not change any conclusion, so you should also report the tolerance you used.