b_asic.operation

Inheritance diagram of b_asic.operation

B-ASIC Operation Module.

Contains the base for operations that are used by B-ASIC.

class b_asic.operation.AbstractOperation(input_count: int, output_count: int, name: str = '', input_sources: Sequence[SignalSourceProvider | None] | None = None, latency: int | None = None, latency_offsets: Dict[str, int] | None = None, execution_time: int | None = None)

Generic abstract operation base class.

Concrete operations should normally derive from this to get the default behavior.

copy(*args, **kwargs) GraphComponent

Get a new instance of this graph component type.

The new instance will have the same name, id, and parameters.

current_output(index: int, delays: Mapping[ResultKey, int | float | complex] | None = None, prefix: str = '') int | float | complex | None

Get the current output at the given index of this operation, if available.

The delays parameter will be used for lookup. The prefix parameter will be used as a prefix for the key string when looking for delays.

current_outputs(delays: Mapping[ResultKey, int | float | complex] | None = None, prefix: str = '') Sequence[int | float | complex | None]

Get all current outputs of this operation, if available.

See also

current_output
property destination: InputPort

Return the InputPort if there is only one input port.

If not, raise a TypeError.

abstract evaluate(*inputs: Operation) List[Operation]
abstract evaluate(*inputs: int | float | complex) List[int | float | complex]

Evaluate the operation and generate a list of output values.

Parameters:
*inputs

List of input values.

evaluate_output(index: int, input_values: Sequence[int | float | complex], results: MutableMapping[ResultKey, int | float | complex | None] | None = None, delays: MutableMapping[ResultKey, int | float | complex] | None = None, prefix: str = '', bits_override: int | None = None, quantize: bool = True) int | float | complex

Evaluate the output at the given index with the given input values.

Parameters:
indexint

Which output to return the value for.

input_valuesarray of float or complex

The input values.

resultsMutableResultMap. optional

Used to store any results (including intermediate results) for caching.

delaysMutableDelayMap. optional

Used to get the current value of any intermediate delay elements that are encountered, and be updated with their new values.

prefixstr, optional

Used as a prefix for the key string when storing results/delays.

bits_overrideint, optional

Specifies a word length override when truncating inputs which ignores the word length specified by the input signal.

quantizebool, default: True

Specifies whether input truncation should be enabled in the first place. If set to False, input values will be used directly without any bit truncation.

evaluate_outputs(input_values: Sequence[int | float | complex], results: MutableMapping[ResultKey, int | float | complex | None] | None = None, delays: MutableMapping[ResultKey, int | float | complex] | None = None, prefix: str = '', bits_override: int | None = None, quantize: bool = True) Sequence[int | float | complex]

Evaluate all outputs of this operation given the input values.

See also

evaluate_output
property execution_time: int | None

Execution time of operation.

get_input_coordinates() Tuple[Tuple[float, float], ...]

Return coordinates for inputs.

These maps to the polygons and are corresponding to a start time of 0 and height 1.

get_output_coordinates() Tuple[Tuple[float, float], ...]

Return coordinates for outputs.

These maps to the polygons and are corresponding to a start time of 0 and height 1.

get_plot_coordinates() Tuple[Tuple[Tuple[float, float], ...], Tuple[Tuple[float, float], ...]]

Return coordinates for the latency and execution time polygons.

This returns a tuple containing coordinates for the two polygons outlining the latency and execution time of the operation. The polygons are corresponding to a start time of 0 and are of height 1.

input(index: int) InputPort

Get the input port at the given index.

property input_count: int

Get the number of input ports.

input_latency_offsets() List[int]
property input_signals: Sequence[Signal]

Get all the signals that are connected to this operation’s input ports.

The signals are ore not ordered.

property inputs: Sequence[InputPort]

Get all input ports.

inputs_required_for_output(output_index: int) Iterable[int]

Get the input indices of all inputs in this operation whose values are required in order to evaluate the output at the given output index.

property is_constant: bool

Return True if the output(s) of the operation is(are) constant.

property is_linear: bool

Return True if the operation is linear.

property is_swappable: bool

Return True if the inputs (and outputs) to the operation can be swapped.

Swapping require that the operation retains the same function, but it is allowed to modify values to do so.

key(index: int, prefix: str = '') ResultKey

Get the key used to access the output of a certain index.

This keu can be used to access the simulation results and used as the output parameter passed to current_output(s) or evaluate_output(s).

property latency: int

Get the latency of the operation.

This is the longest time it takes from one of the input ports to one of the output ports.

property latency_offsets: Dict[str, int | None]

Get a dictionary with all the operations ports latency-offsets.

property neighbors: Iterable[GraphComponent]

Get all components that are directly connected to this operation.

output(index: int) OutputPort

Get the output port at the given index.

property output_count: int

Get the number of output ports.

output_latency_offsets() List[int]
property output_signals: Sequence[Signal]

Get all the signals that are connected to this operation’s output ports.

The signals are ore not ordered.

property outputs: Sequence[OutputPort]

Get all output ports.

property preceding_operations: Iterable[Operation]

Return an Iterable of all Operations that are connected to this Operations input ports.

quantize_input(index: int, value: int | float | complex, bits: int) int | float | complex

Quantize the value to be used as input at the given index to a certain bit length.

quantize_inputs(input_values: Sequence[int | float | complex], bits_override: int | None = None) Sequence[int | float | complex]

Quantize the values to be used as inputs.

The bit lengths are specified by the respective signals connected to each input.

set_latency(latency: int) None

Set the latency of the operation to the specified integer value.

This is done by setting the latency-offsets of operations input ports to 0 and the latency-offsets of the operations output ports to the specified value.

The latency is the time it takes to produce an output from the corresponding input of the underlying operator.

The latency cannot be a negative integer.

Parameters:
latencyint

Non-negative int corresponding to the latency of the operation.

set_latency_offsets(latency_offsets: Dict[str, int]) None

Set the latency-offsets for the operations port.

The latency offsets dictionary should be {‘in0’: 2, ‘out1’: 4} if you want to set the latency offset for the input port with index 0 to 2, and the latency offset of the output port with index 1 to 4.

property source: OutputPort

Return the OutputPort if there is only one output port.

If not, raise a TypeError.

split() Iterable[Operation]

Split the operation into multiple operations.

If splitting is not possible, this may return a list containing only the operation itself.

property subsequent_operations: Iterable[Operation]

Return an Iterable of all Operations that are connected to this Operations output ports.

swap_io() None

Swap inputs (and outputs) of operation.

Errors if is_swappable() is False.

to_sfg() SFG

Convert the operation into its corresponding SFG.

If the operation is composed by multiple operations, the operation will be split.

class b_asic.operation.Operation

Operation interface.

Operations are graph components that perform a certain function. They are connected to each other by signals through their input/output ports.

Operations can be evaluated independently using evaluate_output(). Operations may specify how to quantize inputs through quantize_input().

abstract current_output(index: int, delays: Mapping[ResultKey, int | float | complex] | None = None, prefix: str = '') int | float | complex | None

Get the current output at the given index of this operation, if available.

The delays parameter will be used for lookup. The prefix parameter will be used as a prefix for the key string when looking for delays.

abstract current_outputs(delays: Mapping[ResultKey, int | float | complex] | None = None, prefix: str = '') Sequence[int | float | complex | None]

Get all current outputs of this operation, if available.

See also

current_output
abstract property destination: InputPort

Return the InputPort if there is only one input port.

If not, raise a TypeError.

abstract evaluate_output(index: int, input_values: Sequence[int | float | complex], results: MutableMapping[ResultKey, int | float | complex | None] | None = None, delays: MutableMapping[ResultKey, int | float | complex] | None = None, prefix: str = '', bits_override: int | None = None, quantize: bool = True) int | float | complex

Evaluate the output at the given index with the given input values.

Parameters:
indexint

Which output to return the value for.

input_valuesarray of float or complex

The input values.

resultsMutableResultMap. optional

Used to store any results (including intermediate results) for caching.

delaysMutableDelayMap. optional

Used to get the current value of any intermediate delay elements that are encountered, and be updated with their new values.

prefixstr, optional

Used as a prefix for the key string when storing results/delays.

bits_overrideint, optional

Specifies a word length override when truncating inputs which ignores the word length specified by the input signal.

quantizebool, default: True

Specifies whether input truncation should be enabled in the first place. If set to False, input values will be used directly without any bit truncation.

abstract evaluate_outputs(input_values: Sequence[int | float | complex], results: MutableMapping[ResultKey, int | float | complex | None] | None = None, delays: MutableMapping[ResultKey, int | float | complex] | None = None, prefix: str = '', bits_override: int | None = None, quantize: bool = True) Sequence[int | float | complex]

Evaluate all outputs of this operation given the input values.

See also

evaluate_output
abstract property execution_time: int | None

Get the execution time of the operation.

The execution time is the time between executing two operations on the underlying operator. This is also called initiation interval.

abstract get_input_coordinates() Tuple[Tuple[float, float], ...]

Return coordinates for inputs.

These maps to the polygons and are corresponding to a start time of 0 and height 1.

abstract get_output_coordinates() Tuple[Tuple[float, float], ...]

Return coordinates for outputs.

These maps to the polygons and are corresponding to a start time of 0 and height 1.

abstract get_plot_coordinates() Tuple[Tuple[Tuple[float, float], ...], Tuple[Tuple[float, float], ...]]

Return coordinates for the latency and execution time polygons.

This returns a tuple containing coordinates for the two polygons outlining the latency and execution time of the operation. The polygons are corresponding to a start time of 0 and are of height 1.

abstract input(index: int) InputPort

Get the input port at the given index.

abstract property input_count: int

Get the number of input ports.

abstract property input_signals: Sequence[Signal]

Get all the signals that are connected to this operation’s input ports.

The signals are ore not ordered.

abstract property inputs: Sequence[InputPort]

Get all input ports.

abstract inputs_required_for_output(output_index: int) Iterable[int]

Get the input indices of all inputs in this operation whose values are required in order to evaluate the output at the given output index.

abstract property is_constant: bool

Return True if the output(s) of the operation is(are) constant.

abstract property is_linear: bool

Return True if the operation is linear.

abstract property is_swappable: bool

Return True if the inputs (and outputs) to the operation can be swapped.

Swapping require that the operation retains the same function, but it is allowed to modify values to do so.

abstract key(index: int, prefix: str = '') ResultKey

Get the key used to access the output of a certain index.

This keu can be used to access the simulation results and used as the output parameter passed to current_output(s) or evaluate_output(s).

abstract property latency: int

Get the latency of the operation.

This is the longest time it takes from one of the input ports to one of the output ports.

abstract property latency_offsets: Dict[str, int | None]

Get a dictionary with all the operations ports latency-offsets.

abstract output(index: int) OutputPort

Get the output port at the given index.

abstract property output_count: int

Get the number of output ports.

abstract property output_signals: Sequence[Signal]

Get all the signals that are connected to this operation’s output ports.

The signals are ore not ordered.

abstract property outputs: Sequence[OutputPort]

Get all output ports.

abstract quantize_input(index: int, value: int | float | complex, bits: int) int | float | complex

Quantize the value to be used as input at the given index to a certain bit length.

abstract set_latency(latency: int) None

Set the latency of the operation to the specified integer value.

This is done by setting the latency-offsets of operations input ports to 0 and the latency-offsets of the operations output ports to the specified value.

The latency is the time it takes to produce an output from the corresponding input of the underlying operator.

The latency cannot be a negative integer.

Parameters:
latencyint

Non-negative int corresponding to the latency of the operation.

abstract set_latency_offsets(latency_offsets: Dict[str, int]) None

Set the latency-offsets for the operations port.

The latency offsets dictionary should be {‘in0’: 2, ‘out1’: 4} if you want to set the latency offset for the input port with index 0 to 2, and the latency offset of the output port with index 1 to 4.

abstract property source: OutputPort

Return the OutputPort if there is only one output port.

If not, raise a TypeError.

abstract split() Iterable[Operation]

Split the operation into multiple operations.

If splitting is not possible, this may return a list containing only the operation itself.

abstract swap_io() None

Swap inputs (and outputs) of operation.

Errors if is_swappable() is False.

abstract to_sfg() SFG

Convert the operation into its corresponding SFG.

If the operation is composed by multiple operations, the operation will be split.