test_stateful_numba_model
- test_stateful_numba_model.test_StatefulNumbaDiffusion()[source]
Tests that xStateDiffusionN correctly wires to the StateData diffusion buffer.
- We run a scalar Ornstein-Uhlenbeck process:
dx = theta*(mu - x)*dt + sigma*dW
once using StatefulNumbaModel (diffusion written via xStateDiffusion0 in UpdateStateImpl) and once using StatefulSysModel (diffusion written via setDiffusion in Python UpdateState). With the same integrator seed both simulations must produce bit-identical final states.
- test_stateful_numba_model.test_StatefulNumbaOscillator()[source]
Tests that StatefulNumbaModel works as expected in MJScene.
We use a simple harmonic oscillator with two 3×1 states (pos, vel) and a scalar memory field (omega). The UpdateStateImpl is a Numba cfunc.
posDot = vel velDot = -omega^2 * pos
With pos(0) = [1, 0, 0] and vel(0) = [0, omega, 0] and omega = 2*pi the analytic solution at tf=0.5 s is:
pos[0](tf) = cos(omega * tf) pos[1](tf) = sin(omega * tf) pos[2](tf) = 0
vel[0](tf) = -omega * sin(omega * tf) vel[1](tf) = omega * cos(omega * tf) vel[2](tf) = 0