b_asic.simulation

B-ASIC Simulation Module.

Contains a class for simulating the result of an SFG given a set of input values.

class b_asic.simulation.Simulation(sfg: SFG, input_providers: Sequence[int | float | complex | Sequence[int | float | complex] | Callable[[int], int | float | complex] | None] | None = None)

Bases: object

Simulation of an SFG.

Use FastSimulation (from the C++ extension module) for a more effective simulation when running many iterations.

Parameters:
sfgSFG

The signal flow graph to simulate.

input_providerslist, optional

Input values, one list item per input. Each list item can be an array of values, a callable taking a time index and returning the value, or a number (constant input). If a value is not provided for an input, it will be 0.

clear_results() None

Clear all results that were saved until now.

clear_state() None

Clear all current state of the simulation, except for the results and iteration.

property iteration: int

Get the current iteration number of the simulation.

property results: Mapping[ResultKey, Sequence[int | float | complex]]

A mapping from result keys to numpy arrays containing all results.

This includes intermediate values, calculated for each iteration up until now that was run with save_results enabled. The mapping is indexed using the key() method of Operation with the appropriate output index.

Example result after 3 iterations::

{“c1”: [3, 6, 7], “c2”: [4, 5, 5], “bfly1.0”: [7, 0, 0], “bfly1.1”: [-1, 0, 2], “0”: [7, -2, -1]}

run(save_results: bool = True, bits_override: int | None = None, quantize: bool = True) Sequence[int | float | complex]

Run the simulation until the end of its input arrays.

Return the output values of the last iteration.

Parameters:
save_resultsbool, default: True
bits_overrideint, optional
quantizebool, default: True
run_for(iterations: int, save_results: bool = True, bits_override: int | None = None, quantize: bool = True) Sequence[int | float | complex]

Run a given number of iterations of the simulation.

Return the output values of the last iteration.

Parameters:
iterationsint

Number of iterations to simulate.

save_resultsbool, default: True
bits_overrideint, optional
quantizebool, default: True
run_until(iteration: int, save_results: bool = True, bits_override: int | None = None, quantize: bool = True) Sequence[int | float | complex]

Run the simulation until the iteration number.

Will run until the number of iterations is greater than or equal to the given iteration and return the output values of the last iteration. The number of iterations actually simulated depends on the current state of the Simulation.

Parameters:
iterationint

Iteration number to stop the simulation at.

save_resultsbool, default: True
bits_overrideint, optional
quantizebool, default: True
set_input(index: int, input_provider: int | float | complex | Sequence[int | float | complex] | Callable[[int], int | float | complex]) None

Set the input used to for a specific input index.

Parameters:
indexint

The input index.

input_providerlist, callable, or number

Can be an array of values, a callable taking a time index and returning the value, or a number (constant input).

set_inputs(input_providers: Sequence[int | float | complex | Sequence[int | float | complex] | Callable[[int], int | float | complex] | None]) None

Set the input functions used to get values for the inputs to the internal SFG.

Parameters:
input_providersarray of list, callable, or number
property sfg: SFG

The signal flow graph being simulated.

show() None

Show the simulation results.

step(save_results: bool = True, bits_override: int | None = None, quantize: bool = True) Sequence[int | float | complex]

Run one iteration of the simulation and return the resulting output values.

Parameters:
save_resultsbool, default: True
bits_overrideint, optional
quantizebool, default: True