Skip to content

salvus.flow.acta.memo.toy_flow

salvus.flow.acta.memo.toy_flow salvus flow acta memo toy_flow

Arithmetic tasks for exercising memoization.

Functions

add()

def add(a: float, b: float) -> float: ...

Return a + b.

Parameters
  • a float — Left addend.
  • b float — Right addend.
Returns float

multiply()

def multiply(a: float, b: float) -> float: ...

Return a * b.

Parameters
  • a float — Left factor.
  • b float — Right factor.
Returns float

negate()

def negate(a: float) -> float: ...

Return -a.

Parameters
  • a float — The value to negate.
Returns float

run_toy_task()

def run_toy_task(
    store: ContentStoreBase,
    records: RecordStore,
    task: str,
    compute: Callable[..., float],
    spec: BaseModel,
    inputs: Mapping[str, float],
    impl_version: int = 1,
) -> ToyTaskResult: ...

Run one toy task through the full memoization protocol.

Parameters
  • store ContentStoreBase — Content store backing both inputs and outputs.
  • records RecordStore — Record store to look up and commit against.
  • task str — Task name, part of the envelope.
  • compute Callable[..., float] — The pure function to call on a miss. Called as compute(**inputs, **spec.model_dump()).
  • spec BaseModel — Frozen spec carrying this task’s non-input parameters (e.g. ScaleSpec’s factor). Use EmptySpec for tasks with no such parameters.
  • inputs Mapping[str, float] — Input names mapped to float values.
  • impl_version int = 1 — The task’s implementation version.
Returns ToyTaskResult — The task’s result, annotated with whether it was a cache hit.

scale()

def scale(a: float, factor: float) -> float: ...

Return a * factor.

Parameters
  • a float — The value to scale.
  • factor float — Multiplier from ScaleSpec.
Returns float

square()

def square(a: float) -> float: ...

Return a * a.

Parameters
  • a float — The value to square.
Returns float

subtract()

def subtract(reference: float, perturbed: float) -> float: ...

Return reference - perturbed.

Parameters
  • reference float — The baseline value.
  • perturbed float — The value being compared against the baseline.
Returns float

Classes

EmptySpec

class EmptySpec(salvus.flow.acta.memo.toy_flow._Frozen):
    def __init__(self, **data):
        ...

Spec for toy tasks that take no parameters beyond their inputs.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Attributes
model_extra Dict[str, Any] | None

Get extra fields set during validation.

Returns: A dictionary of extra fields, or None if config.extra is not set to "allow".

model_fields_set set[str]

Returns the set of fields that have been explicitly set on this model instance.

Returns: A set of strings representing the fields that have been set, i.e. that were not filled from defaults.

ScaleSpec

class ScaleSpec(salvus.flow.acta.memo.toy_flow._Frozen):
    def __init__(self, **data):
        ...

Spec for scale.

Args: factor: Multiplier applied to the single input.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Attributes
model_extra Dict[str, Any] | None

Get extra fields set during validation.

Returns: A dictionary of extra fields, or None if config.extra is not set to "allow".

model_fields_set set[str]

Returns the set of fields that have been explicitly set on this model instance.

Returns: A set of strings representing the fields that have been set, i.e. that were not filled from defaults.

ToyTaskResult

class ToyTaskResult(builtins.object):
    def __init__(self, value: float, key: str, was_hit: bool) -> None: ...

Outcome of one run_toy_task call.

Parameters
  • value float — The task’s output value, whether freshly computed or replayed from a hit.
  • key str — The envelope key this execution was looked up/committed under.
  • was_hit bool — True if the result was served from a verified cache hit, False if it was freshly computed.