Skip to content

Docstring example for a fully custom simulator raises AxisError #306

Description

@AlexanderFengler

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions