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()
add()def add(a: float, b: float) -> float: ...Return a + b.
afloat — Left addend.bfloat — Right addend.
multiply()
multiply()def multiply(a: float, b: float) -> float: ...Return a * b.
afloat — Left factor.bfloat — Right factor.
negate()
negate()def negate(a: float) -> float: ...Return -a.
afloat — The value to negate.
run_toy_task()
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.
storeContentStoreBase — Content store backing both inputs and outputs.recordsRecordStore — Record store to look up and commit against.taskstr — Task name, part of the envelope.computeCallable[..., float] — The pure function to call on a miss. Called ascompute(**inputs, **spec.model_dump()).specBaseModel — Frozen spec carrying this task’s non-input parameters (e.g.ScaleSpec’sfactor). UseEmptySpecfor tasks with no such parameters.inputsMapping[str, float] — Input names mapped to float values.impl_versionint =1— The task’s implementation version.
scale()
scale()def scale(a: float, factor: float) -> float: ...Return a * factor.
afloat — The value to scale.factorfloat — Multiplier fromScaleSpec.
square()
square()def square(a: float) -> float: ...Return a * a.
afloat — The value to square.
subtract()
subtract()def subtract(reference: float, perturbed: float) -> float: ...Return reference - perturbed.
referencefloat — The baseline value.perturbedfloat — The value being compared against the baseline.
Classes
EmptySpec
EmptySpecclass 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.
model_extra Dict[str, Any] | None
model_extra Dict[str, Any] | NoneGet 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]
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
ScaleSpecclass 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.
model_extra Dict[str, Any] | None
model_extra Dict[str, Any] | NoneGet 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]
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
ToyTaskResultclass ToyTaskResult(builtins.object):
def __init__(self, value: float, key: str, was_hit: bool) -> None: ...Outcome of one run_toy_task call.
valuefloat — The task’s output value, whether freshly computed or replayed from a hit.keystr — The envelope key this execution was looked up/committed under.was_hitbool —Trueif the result was served from a verified cache hit,Falseif it was freshly computed.