test_numbaModel

Unit tests for NumbaModel.

Section Topic ——- ———————————————————————- 1 Basic scalar I/O + memory namespace (smoke test) 2 Auto-convert scalar / list memory at Reset time 3 Post-Reset convenience writes via memory namespace 4 CurrentSimNanos parameter 5 IsLinked: scalar reader (unlinked, linked, becomes linked mid-sim) 6 Message chain: producer -> consumer (scalar I/O, memory) 7 List readers: all linked, partial link (IsLinked array) 8 List writers 9 Dict readers: key introspection, data round-trip, unlinked error 10 Dict writers 11 2-D memory array 12 moduleID parameter 13 Re-wiring: subscribeTo after Reset 14 Memory persistence across resets 15 Error cases (incl. empty containers, empty memory) 16 Dict reader IsLinked keyed access 17 bskLogger proxy

class test_numbaModel.AutoConvertModel(*args, **kwargs)[source]

Bases: NumbaModel

Model used to verify scalar and list memory auto-conversion.

static UpdateStateImpl(dataOutMsgPayload, memory)[source]

Write the gain-plus-bias result into the outgoing message.

class test_numbaModel.BasicModel(*args, **kwargs)[source]

Bases: NumbaModel

Minimal scalar input/output model with one integer memory field.

static UpdateStateImpl(dataInMsgPayload, dataInMsgIsLinked, dataOutMsgPayload, CurrentSimNanos, memory)[source]

Forward the input vector when linked and increment the step count.

class test_numbaModel.ConsumerModel(*args, **kwargs)[source]

Bases: NumbaModel

Sink model that scales the producer output by a fixed factor.

static UpdateStateImpl(dataInMsgPayload, dataInMsgIsLinked, dataOutMsgPayload)[source]

Copy the input vector into the output after multiplying by ten.

class test_numbaModel.DictInModel(*args, **kwargs)[source]

Bases: NumbaModel

Dictionary-based input reader model used for key-order tests.

static UpdateStateImpl(dataInMsgPayload, dataOutMsgPayload)[source]

Route the named inputs into separate output vector components.

class test_numbaModel.DictOutModel(*args, **kwargs)[source]

Bases: NumbaModel

One input reader → two named output messages.

static UpdateStateImpl(dataInMsgPayload, dataInMsgIsLinked, dataOutMsgPayload)[source]

Write positive and negative copies of the input value.

class test_numbaModel.GuardedReaderModel(*args, **kwargs)[source]

Bases: NumbaModel

Forwards payload when linked; writes sentinel −1 when unlinked.

static UpdateStateImpl(dataInMsgPayload, dataInMsgIsLinked, dataOutMsgPayload, memory)[source]

Copy the input when linked and publish a sentinel otherwise.

class test_numbaModel.MatrixMemoryModel(*args, **kwargs)[source]

Bases: NumbaModel

Stores a 3×3 diagonal matrix; outputs the diagonal each tick.

static UpdateStateImpl(dataOutMsgPayload, memory)[source]

Copy the matrix diagonal into the output vector.

class test_numbaModel.ModuleIDModel(*args, **kwargs)[source]

Bases: NumbaModel

Helper model that captures the module ID seen by the compiled kernel.

static UpdateStateImpl(dataOutMsgPayload, memory, moduleID)[source]

Store the provided module identifier in persistent memory.

class test_numbaModel.MultiInModel(*args, **kwargs)[source]

Bases: NumbaModel

Two input readers summed into one output.

static UpdateStateImpl(dataInMsgPayload, dataInMsgIsLinked, dataOutMsgPayload)[source]

Sum the first component from each linked reader.

class test_numbaModel.MultiOutModel(*args, **kwargs)[source]

Bases: NumbaModel

One input reader → two indexed output writers.

static UpdateStateImpl(dataInMsgPayload, dataInMsgIsLinked, dataOutMsgPayload)[source]

Write the input value and its doubled copy to the outputs.

class test_numbaModel.ProducerModel(*args, **kwargs)[source]

Bases: NumbaModel

Source model used to exercise chained message passing.

static UpdateStateImpl(dataOutMsgPayload, memory)[source]

Increment the counter and publish three scaled copies.

class test_numbaModel.TimeRecorderModel(*args, **kwargs)[source]

Bases: NumbaModel

Records the last simulation time and a tick counter in memory.

static UpdateStateImpl(dataOutMsgPayload, CurrentSimNanos, memory)[source]

Store the current simulation time and publish it as a float.

test_numbaModel.test_2dMemoryArrayPythonWrite()[source]

Python-side assignment to a 2-D memory field propagates to the C buffer.

test_numbaModel.test_2dMemoryArrayRead()[source]

Cfunc reads 2-D memory field correctly.

test_numbaModel.test_autoConvertMemory()[source]

Check scalar and list memory fields are converted at reset.

test_numbaModel.test_basicModel()[source]

Smoke-test scalar I/O and persistent memory updates.

test_numbaModel.test_bsklogger()[source]

bskLog / bskLog1 inside UpdateStateImpl should not crash; logic must run.

test_numbaModel.test_cacheDiskImplBodyChange(tmp_path)[source]

Edit UpdateStateImpl on disk between processes and require the new implementation to run.

This verifies the full production invalidation chain. The implementation body hash changes, the fingerprint changes, a new wrapper file is emitted, and Numba recompiles the implementation after its source timestamp changes. A stale-cache bug would show up as process 2 still returning 11.0.

test_numbaModel.test_cacheDiskReuseAfterInProcessClear()[source]

Clear _NBMODEL_CFUNC_CACHE, re-run same config → disk path gives correct result.

test_numbaModel.test_cacheDiskSurvivesProcessRestart(tmp_path)[source]

Disk cache written in process 1 is used correctly by process 2.

test_numbaModel.test_cacheImplIdentityIsolation()[source]

Two classes with same dtype/structure but different UpdateStateImpl must not share cfunc.

test_numbaModel.test_cacheLoggerLevelRuntime(monkeypatch, tmp_path, capfd)[source]

Logger level is read at runtime; models with different levels share one cfunc.

test_numbaModel.test_cacheMultipleResetsReusesCfunc()[source]

Re-running InitializeSimulation reuses the in-process cfunc (Tier 2 benefit).

test_numbaModel.test_cacheNoDtypeCollision()[source]

Same class, different reader dtypes → distinct fingerprints, no in-process collision.

Regression test for the location-based idHash bug: md5(file:qualname) produced the same key for all instances of a class regardless of message-type configuration.

test_numbaModel.test_cacheSameDtypeSharesCfunc()[source]

Two instances with identical dtype config share exactly one cfunc.

test_numbaModel.test_cacheSharedCfuncIndependentState()[source]

Two instances share one cfunc but each has its own allPtrs_ buffer, so outputs never bleed.

test_numbaModel.test_currentSimNanos()[source]

Check the compiled model receives the current simulation time.

test_numbaModel.test_dictIslinkedKeyed()[source]

Dict reader IsLinked is accessible by key name: dataInMsgIsLinked[‘a’].

test_numbaModel.test_dictReaderData()[source]

Payload from each dict key is routed to the correct output field.

test_numbaModel.test_dictReaderKeys()[source]

Key order is preserved and accessible from Python after Reset.

test_numbaModel.test_dictWriter()[source]

Check dictionary-based output messages are written by key.

test_numbaModel.test_emptyListReader()[source]

Empty list attribute is allowed; cfunc receives a zero-element array (never iterated).

test_numbaModel.test_emptyMemory()[source]

No memory fields defined: ‘memory’ param still compiles as a valid (ignored) Record.

test_numbaModel.test_errorIslinkedWithoutPayload()[source]

An IsLinked flag without a matching Payload param leaves the variable undefined in the generated wrapper, which Numba catches as a TypingError.

test_numbaModel.test_errorMissingInMsg()[source]

Check Reset fails when a referenced input message is missing.

test_numbaModel.test_errorNotOverridden()[source]

Check Reset fails when UpdateStateImpl is not overridden.

test_numbaModel.test_errorNotStaticmethod()[source]

Check Reset fails when UpdateStateImpl is not static.

test_numbaModel.test_errorUnlinkedWithoutIslinkedGuard()[source]

Declaring InMsgPayload without InMsgIsLinked crashes at reset if a reader is unlinked.

test_numbaModel.test_errorUnrecognisedParam()[source]

Check Reset fails when the compiled signature has an unknown parameter.

test_numbaModel.test_islinkedBecomesLinkedMidSim()[source]

Reader starts unlinked; subscribed after first tick - cfunc picks it up.

test_numbaModel.test_islinkedLinked()[source]

Subscribed reader → IsLinked is True; payload is forwarded.

test_numbaModel.test_islinkedUnlinked()[source]

Unlinked reader → IsLinked is False; cfunc takes the else branch.

test_numbaModel.test_listReaderBothLinked()[source]

Both readers subscribed → sum of both sources.

test_numbaModel.test_listReaderNoneLinked()[source]

Both readers unlinked → output stays zero.

reader[0] subscribed, reader[1] unlinked → only reader[0] contributes.

test_numbaModel.test_listWriter()[source]

Check list-based output messages are written by index.

test_numbaModel.test_memoryWritePersistsThroughReset()[source]

Both Python-side writes and cfunc-internal writes survive a subsequent Reset.

test_numbaModel.test_messageChain()[source]

Check a NumbaModel output can feed another NumbaModel input.

test_numbaModel.test_moduleIdParameter()[source]

Check the compiled model receives the owning module identifier.

test_numbaModel.test_multipleResets()[source]

Reset always continues from the current buffer value; cfunc writes and Python writes are treated identically.

test_numbaModel.test_postResetConvenienceWrite()[source]

Check post-reset memory writes update existing fields and reject new ones.

test_numbaModel.test_rewireAfterReset()[source]

Switching sources mid-sim is transparent - no Reset required.