lnccbrown / lnccbrown/ssm-simulators
Docstring example for a fully custom simulator raises AxisError
- Dominant language
- Jupyter Notebook
- Stars
- 24
- Forks
- 18
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 9
Description
The "Fully custom simulator" example in the `Simulator` class docstring
(`ssms/basic_simulators/simulator_class.py`) raises when run verbatim.
The example returns 1-D `rts`/`choices`, but `Simulator.simulate()` calls
`np.squeeze(x["rts"], axis=1)` (`simulator_class.py:675`), which requires a
second axis.
This matters more than a typical docstring slip because it is the documented
entry point for the "bring your own model" workflow, and it is copy-pasteable.
### Reproducer
```python
import numpy as np
from ssms.basic_simulators.simulator_class import Simulator
# verbatim from the docstring
def my_sim(v, a, z, t, max_t=20, n_samples=1000, **kwargs):
rts = np.random.exponential(1/abs(v), n_samples) + t
choices = np.where(np.random.random(n_samples) < z, 1, -1)
return {'rts': rts, 'choices': choices,
'metadata': {'model': 'custom', 'n_samples': n_samples}}
sim = Simulator(simulator_function=my_sim, params=["v", "a", "z", "t"], nchoices=2)
results = sim.simulate(theta={'v': 0.5, 'a': 1.0, 'z': 0.5, 't': 0.3})
```
```
File ".../ssms/basic_simulators/simulator_class.py", line 675, in simulate
x["rts"] = np.squeeze(x["rts"], axis=1)
numpy.exceptions.AxisError: axis 1 is out of bounds for array of dimension 1
```
Returning `(n_samples, 1)` arrays instead works.
### Possible fixes
Either update the docstring to require `(n_samples, 1)`, or promote 1-D returns
to 2-D in `simulate()` before the squeeze.
Also note the same call emits three warnings about `my_sim` missing `max_t`,
`delta_t` and `random_state` — but the docstring example only declares `max_t`,
so following the docs guarantees warnings.
**Version:** ssm-simulators 0.13.2, numpy 2.4.6, Python 3.12
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in ssms/basic_simulators/simulator_class.py, reading the Fully custom simulator docstring and simulate() around line 675. Run the reproducer from the issue, then verify the chosen fix makes the example run without AxisError and that its documented callback arguments do not produce the noted warnings.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, python
- Domain
- backend-api-design, documentation
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 76/100