da4ml.trace package
Subpackages
Submodules
da4ml.trace.fixed_variable module
- class da4ml.trace.fixed_variable.FixedVariable(low: float | Decimal, high: float | Decimal, step: float | Decimal, latency: float | None = None, hwconf: HWConfig | tuple[int, int, int] = (-1, -1, -1), opr: str = 'new', cost: float | None = None, _from: tuple[FixedVariable, ...] = (), _factor: float | Decimal = 1.0, _data: Decimal | None = None, _id: UUID | None = None)
Bases:
object- abs()
Get the absolute value of this variable.
- classmethod from_kif(k: int | bool, i: int, f: int, **kwargs)
- get_cost_and_latency() tuple[float, float]
- is_negative() FixedVariable | bool
- is_positive() FixedVariable | bool
- property kif: tuple[bool, int, int]
- lookup(table: LookupTable | ndarray) FixedVariable
Use a lookup table to map the variable. When the table is a numpy array, the table starts at the lowest possible value of the variable When the table is in LookupTable format, the table starts at the normalized lowest value of the variable. (i.e., if the variable has negative _factor, the table is reversed)
- Parameters:
table (LookupTable | np.ndarray) – Lookup table to use
- Return type:
- max_of(other)
Get the maximum of this variable and another variable or constant.
- min_of(other)
Get the minimum of this variable and another variable or constant.
- msb_mux(a: FixedVariable | float | Decimal, b: FixedVariable | float | Decimal, qint: tuple[Decimal, Decimal, Decimal] | None = None)
If the MSB of this variable is 1, return a, else return b. When the variable is signed, the MSB is determined by the sign bit (1 for <0, 0 for >=0)
- quantize(k: int | bool, i: int, f: int, overflow_mode: str = 'WRAP', round_mode: str = 'TRN') FixedVariable
Quantize the variable to the specified fixed-point format.
- Parameters:
k (int | bool) – Sign bit (True for signed, False for unsigned)
i (int) – Integer bits, excluding sign bit
f (int) – Fraction bits
overflow_mode (str, optional) – Overflow mode, one of ‘WRAP’, ‘SAT’, ‘SAT_SYM’, by default ‘WRAP’
round_mode (str, optional) – Rounding mode, one of ‘TRN’ (truncate), ‘RND’ (round to nearest, half up), by default ‘TRN’
- relu(i: int | None = None, f: int | None = None, round_mode: str = 'TRN')
- property unscaled
- class da4ml.trace.fixed_variable.FixedVariableInput(latency: float | None = None, hwconf: HWConfig | tuple[int, int, int] = (-1, -1, -1), opr: str = 'new')
Bases:
FixedVariable- max_of(other)
Get the maximum of this variable and another variable or constant.
- min_of(other)
Get the minimum of this variable and another variable or constant.
- quantize(k: int | bool, i: int, f: int, overflow_mode: str = 'WRAP', round_mode: str = 'TRN')
Quantize the variable to the specified fixed-point format.
- Parameters:
k (int | bool) – Sign bit (True for signed, False for unsigned)
i (int) – Integer bits, excluding sign bit
f (int) – Fraction bits
overflow_mode (str, optional) – Overflow mode, one of ‘WRAP’, ‘SAT’, ‘SAT_SYM’, by default ‘WRAP’
round_mode (str, optional) – Rounding mode, one of ‘TRN’ (truncate), ‘RND’ (round to nearest, half up), by default ‘TRN’
- relu(*args, **kwargs)
- class da4ml.trace.fixed_variable.HWConfig(adder_size, carry_size, latency_cutoff)
Bases:
NamedTuple- adder_size: int
Alias for field number 0
- carry_size: int
Alias for field number 1
- latency_cutoff: float
Alias for field number 2
- class da4ml.trace.fixed_variable.LookupTable(values: ndarray[tuple[Any, ...], dtype[_ScalarT]], spec: TableSpec | None = None)
Bases:
object- property float_table: ndarray[tuple[Any, ...], dtype[floating]]
- classmethod from_dict(data: dict) LookupTable
- lookup(var: FixedVariable, qint_in: QInterval) FixedVariable
- lookup(var: floating | float, qint_in: QInterval | tuple[float, float, float]) float
- to_dict() dict
- class da4ml.trace.fixed_variable.TableSpec(hash: str, out_qint: da4ml.cmvm.types.QInterval, inp_width: int)
Bases:
object- hash: str
- inp_width: int
- property out_kif: tuple[bool, int, int]
- class da4ml.trace.fixed_variable.TraceContext
Bases:
object- get_table_from_index(index: int) LookupTable
- index_table(hash: str) int
- register_table(table: LookupTable | ndarray)
- da4ml.trace.fixed_variable.interpret_as(x: ndarray[tuple[Any, ...], dtype[integer]], k: int, i: int, f: int) ndarray[tuple[Any, ...], dtype[floating]]
- da4ml.trace.fixed_variable.interpret_as(x: int, k: int, i: int, f: int) float
- da4ml.trace.fixed_variable.to_csd_powers(x: float) Generator[float, None, None]
Convert a float to a list of +/- powers of two in CSD representation.
da4ml.trace.fixed_variable_array module
- class da4ml.trace.fixed_variable_array.FixedVariableArray(vars: ndarray[tuple[Any, ...], dtype[_ScalarT]], solver_options: solver_options_t | None = None)
Bases:
objectSymbolic array of FixedVariable for tracing operations. Supports numpy ufuncs and array functions.
- property T
- apply(fn: Callable[[ndarray[tuple[Any, ...], dtype[_ScalarT]]], ndarray[tuple[Any, ...], dtype[_ScalarT]]]) RetardedFixedVariableArray
Apply a unary operator to all elements, returning a RetardedFixedVariableArray.
- property collapsed
- property dtype
- flatten()
- classmethod from_kif(k: ndarray[tuple[Any, ...], dtype[bool | integer]], i: ndarray[tuple[Any, ...], dtype[integer]], f: ndarray[tuple[Any, ...], dtype[integer]], hwconf: HWConfig | tuple[int, int, int] = (1, -1, -1), latency: ndarray[tuple[Any, ...], dtype[floating]] | float = 0.0, solver_options: solver_options_t | None = None)
- classmethod from_lhs(low: ndarray[tuple[Any, ...], dtype[floating]], high: ndarray[tuple[Any, ...], dtype[floating]], step: ndarray[tuple[Any, ...], dtype[floating]], hwconf: HWConfig | tuple[int, int, int] = (1, -1, -1), latency: ndarray | float = 0.0, solver_options: solver_options_t | None = None)
- property kif
[k, i, f] array
- property latency
Maximum latency among all elements.
- property lhs
[low, high, step] array
- matmul(other) FixedVariableArray
- property ndim
- quantize(k: ndarray[tuple[Any, ...], dtype[integer]] | integer | int | None = None, i: ndarray[tuple[Any, ...], dtype[integer]] | integer | int | None = None, f: ndarray[tuple[Any, ...], dtype[integer]] | integer | int | None = None, overflow_mode: str = 'WRAP', round_mode: str = 'TRN')
- ravel()
- relu(i: ndarray[tuple[Any, ...], dtype[integer]] | None = None, f: ndarray[tuple[Any, ...], dtype[integer]] | None = None, round_mode: str = 'TRN')
- reshape(*shape)
- rmatmul(other)
- property shape
- property size
- transpose(axes=None)
- class da4ml.trace.fixed_variable_array.FixedVariableArrayInput(shape: tuple[int, ...] | int, hwconf: HWConfig | tuple[int, int, int] = (1, -1, -1), solver_options: solver_options_t | None = None, latency=0.0)
Bases:
FixedVariableArraySimilar to FixedVariableArray, but initializes all elements as FixedVariableInput - the precisions are unspecified when initialized, and the highest precision requested (i.e., quantized to) will be recorded for generation of the logic.
- class da4ml.trace.fixed_variable_array.RetardedFixedVariableArray(vars: ndarray[tuple[Any, ...], dtype[_ScalarT]], solver_options: solver_options_t | None, operator: Callable[[ndarray[tuple[Any, ...], dtype[_ScalarT]]], ndarray[tuple[Any, ...], dtype[_ScalarT]]])
Bases:
FixedVariableArrayEphemeral FixedVariableArray generated from operations of unspecified output precision. This object translates to normal FixedVariableArray upon quantization. Does not inherit the maximum precision like FixedVariableArrayInput.
This object can be used in two ways: 1. Quantization with specified precision, which converts to FixedVariableArray. 2. Apply an further unary operation, which returns another RetardedFixedVariableArray. (e.g., composite functions)
- apply(fn: Callable[[ndarray[tuple[Any, ...], dtype[_ScalarT]]], ndarray[tuple[Any, ...], dtype[_ScalarT]]]) RetardedFixedVariableArray
Apply a unary operator to all elements, returning a RetardedFixedVariableArray.
- property kif
[k, i, f] array
- quantize(k: ndarray[tuple[Any, ...], dtype[integer]] | integer | int | None = None, i: ndarray[tuple[Any, ...], dtype[integer]] | integer | int | None = None, f: ndarray[tuple[Any, ...], dtype[integer]] | integer | int | None = None, overflow_mode: str = 'WRAP', round_mode: str = 'TRN')
- da4ml.trace.fixed_variable_array.cmvm(cm: ndarray, v: FixedVariableArray, solver_options: solver_options_t) ndarray
- da4ml.trace.fixed_variable_array.make_table(fn: Callable[[ndarray[tuple[Any, ...], dtype[_ScalarT]]], ndarray[tuple[Any, ...], dtype[_ScalarT]]], qint: QInterval) LookupTable
- da4ml.trace.fixed_variable_array.mmm(mat0: ndarray, mat1: ndarray)
- da4ml.trace.fixed_variable_array.to_raw_arr(obj: T) T
da4ml.trace.pipeline module
- da4ml.trace.pipeline.to_pipeline(comb: CombLogic, latency_cutoff: float, retiming=True, verbose=True) Pipeline
Split the record into multiple stages based on the latency of the operations. Only useful for HDL generation.
- Parameters:
sol (CombLogic) – The combinational logic to be pipelined into multiple stages.
latency_cutoff (float) – The latency cutoff for splitting the operations.
retiming (bool) – Whether to retime the solution after splitting. Default is True. If False, new stages are created when the propagation latency exceeds the cutoff. If True, after the first round of splitting, the solution is retimed balance the delay within each stage.
verbose (bool) – Whether to print the actual cutoff used for splitting. Only used if rebalance is True. Default is True.
- Returns:
The cascaded solution with multiple stages.
- Return type:
CascadedSolution
da4ml.trace.tracer module
- da4ml.trace.tracer.gather_variables(inputs: Sequence[FixedVariable], outputs: Sequence[FixedVariable])