b_asic.multirate

Construct multi-rate graphs with Expansion and Compression. Expansion inserts zeros; compression retains one phase of every group of input samples. Both operations accept a positive integer factor and an optional phase.

Simulation accepts these graphs directly. It normalizes an internal copy into a graph that processes one common period per iteration. The original graph remains available through simulation.sfg. Input providers use their own local sample indices, and saved result arrays contain consecutive samples at each signal’s own rate. Arrays for different signals can consequently have different lengths.

For example, compression by three consumes three input samples and produces one output sample per iteration. Expansion by three consumes one and produces three. input_samples_per_iteration and output_samples_per_iteration expose those counts. Run methods return the last sample of each output in the last period. Finite input arrays must contain whole periods and represent the same number of periods across inputs; partial periods are currently rejected.

Call to_single_rate() to obtain the normalized graph and its phase mappings explicitly. The normalized graph contains ordinary operations, zero constants, and Sinks on unused phases. It can be simplified with constant and sink propagation before scheduling. The phase mappings refer to the graph before simplification. Unfolding and state-space analysis also require the normalized graph. For FastSimulation, normalize explicitly and supply one input provider per phase port; direct multi-rate execution uses the Python Simulation class.

Normalize fixed integer sample-rate changes into a single-rate phase graph.

class b_asic.multirate.RateNormalization(sfg: SFG, input_samples: tuple[int, ...], output_samples: tuple[int, ...], input_phases: tuple[tuple[int, int], ...], output_phases: tuple[tuple[int, int], ...], result_phases: dict[ResultKey, tuple[ResultKey, ...]])

Bases: object

A single-rate graph and the stream layout of one common iteration period.

input_samples and output_samples give the number of samples per original port in a period. input_phases and output_phases describe the corresponding scalar ports of sfg as (original_port, phase). Ports are grouped by original port, with phases in chronological order. Disconnected input components use the same reference input sample rate.

result_phases maps each original result key to the single-rate result keys for its consecutive samples within a period. Several original keys may refer to the same result after rate-changing operations become wiring. The phase mappings describe sfg before any further simplification.

input_phases: tuple[tuple[int, int], ...]
input_samples: tuple[int, ...]
output_phases: tuple[tuple[int, int], ...]
output_samples: tuple[int, ...]
result_phases: dict[ResultKey, tuple[ResultKey, ...]]
sfg: SFG