Simulating models¶
A Trace holds input values over time. The
Simulator propagates them through the circuit
and fills in the watched nets.
import intrepyd as ip
ctx = ip.Context()
bool_t, int8_t = ctx.mk_boolean_type(), ctx.mk_int8_type()
tick = ctx.mk_input('tick', bool_t)
count = ctx.mk_latch('count', int8_t)
ctx.set_latch_init_next(
count,
ctx.mk_number('0', int8_t),
ctx.mk_ite(tick, ctx.mk_add(count, ctx.mk_number('1', int8_t)), count))
trace = ctx.mk_trace()
for depth in range(5):
trace.set_value(tick, depth, 'true' if depth % 2 == 0 else 'false')
simulator = ctx.mk_simulator()
simulator.add_watch(count)
simulator.simulate(trace, 4)
for name, values in trace.get_as_net_dictionary(ctx.net2name).items():
print(name, ' '.join(values))
Booleans are T / F, and ? marks a value the engine left unconstrained.
Traces as data¶
Traces are plain dictionaries: get_as_net_dictionary(ctx.net2name) gives
name -> [value@0, value@1, ...], get_as_depth_dictionary() depth -> the
values at that depth, and set_from_dictionary(values, ctx.inputs) fills a
trace from the first kind, taking the inputs only.
intrepyd.tools.simulate() wraps this into a
CSV-driven workflow (read_trace_csv, write_trace_csv), and
intrepyd.plots draws a trace as a timing diagram
(plot_trace_dictionary).