Firing¶
firing
¶
Optional host-side records of accepted stochastic reaction firings.
FiringRecorder(channels=None)
¶
Record selected channels in output intervals, without adding state rows.
Counts are NumPy int64 diagnostics, even when the evolving state uses another
namespace. Intervals are (t[i], t[i+1]]. A forcing change wins a tie with
a candidate event, so that discarded event is not counted. Reusing a recorder
starts a fresh record. Recording never consumes random numbers.
Examples:
>>> import numpy as np
>>> from op_engine import DirectSSASolver, ModelCore
>>> core = ModelCore(2, 1, np.array([0.0, 1.0]))
>>> core.set_initial_state(np.array([[10.0], [0.0]]))
>>> counts = FiringRecorder((0,))
>>> solver = DirectSSASolver(core, np.array([[-1.0], [1.0]]))
>>> def hazards(time, state):
... return state[:1]
>>> solver.run(hazards, rng=np.random.default_rng(4), recorder=counts)
>>> counts.counts.shape, counts.cumulative.shape
((1, 1, 1), (2, 1, 1))
>>> int(counts.counts.sum()) == int(core.state_array[-1, 1, 0])
True
Select local reaction indices; None records every channel.
Raises:
| Type | Description |
|---|---|
ValueError
|
Channel selections contain invalid or duplicate indices. |
Source code in src/op_engine/firing.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
counts
property
¶
Return read-only (interval, selected channel, batch...) counts.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
The recorder has not been attached to a run. |
cumulative
property
¶
Return cumulative counts at output times, including an initial zero.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
Recording has not started or cumulative counts overflow. |
record(interval, flat_event_index)
¶
Count one accepted event in its channel and batch cell.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
Recording has not started or an interval count overflows. |
Source code in src/op_engine/firing.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
record_counts(interval, firings)
¶
Add an accepted firing-count array to one output interval.
The input uses the reaction layout supplied to :meth:start. Only
selected channels are copied to the host; no random draws are made.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
Recording has not started or a count overflows int64. |
ValueError
|
The interval, shape, or selected counts are invalid. |
TypeError
|
Firing counts cannot be transferred to the host eagerly. |
Source code in src/op_engine/firing.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |
start(n_intervals, reaction_shape, reaction_axis)
¶
Allocate a fresh record for a solver's validated reaction layout.
Raises:
| Type | Description |
|---|---|
ValueError
|
A selected channel is outside the reaction layout. |
Source code in src/op_engine/firing.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |