Skip to main content

A package to manage interdependent fields

Project description

Revalidate

A package to manage interdependent fields.

Installation

Install the package with pip:

pip install revalidate

What revalidate does

Imagine you write a class that represents a system and has two inputs and three outputs. Users can set any of the input values and query all input and output values. Let's assume that the computation of the output values is expensive. So, we only want to compute an output value if necessary. A first approach is to cache the output values. But what happens when in input changes? Do all outputs values need to be recomputed or are some still valid? The package revalidate keeps track of dependencies between values and knows when a value needs to be recomputed (or revalidated).

The class for the System could look as follows:

# coding=utf-8

from revalidate import variable, VariableBase, compute

class System(VariableBase):
    input_1: float = variable()
    input_2: float = variable()

    output_1 = variable(depends_on=["input_1", "input_2"], read_only=True)
    output_2 = variable(depends_on=["input_2"], read_only=True)
    output_3 = variable(depends_on=["output_1"], read_only=True)

    def __init__(self, input_1, input_2):
        self.input_1 = input_1
        self.input_2 = input_2

    @compute("output_1")
    def _compute_output_1(self):
        return self.input_1 + self.input_2

    @compute("output_2")
    def _compute_2(self):
        return 2 * self.input_2

    @compute("output_3")
    def _compute_3(self):
        return 2 * self.output_1

First, the class System must inherit from VariableBase in order for the following code to work. Then, the input and output variables are defined on the class with the variable keyword. For each variable, the dependencies are given here. This information is used internally to mark variables invalid when one of its dependencies changes. For example, if input_1 changes, output_1 becomes invalid because it depends on input_1. As a consequence, output_2 becomes also invalid because it depends on outpt_1 which just became invalid.

There is a compute function, marked with the decorator compute, defined for all output variables. These functions are used to compute the value of a variable from other variables on the object. They are only called if necessary.

Contribution

Clone the repo and run

uv sync --extra dev

to set up the development environment.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

revalidate-0.1.0.tar.gz (39.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

revalidate-0.1.0-py3-none-any.whl (22.5 kB view details)

Uploaded Python 3

File details

Details for the file revalidate-0.1.0.tar.gz.

File metadata

  • Download URL: revalidate-0.1.0.tar.gz
  • Upload date:
  • Size: 39.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for revalidate-0.1.0.tar.gz
Algorithm Hash digest
SHA256 86e04e14b070e3a433de972f5da97a248bd07e3b53bdc08dc0165fd269842e77
MD5 cc017308a047962cb3fa6ab167036055
BLAKE2b-256 32029899f6d0bc2e185561ce92ab7a9750699c5f90d6186b2accc062c489fd03

See more details on using hashes here.

File details

Details for the file revalidate-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: revalidate-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 22.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for revalidate-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 62b598e468057b3672e98eec97fe8c966e6491803eed068d0693fc74494eac2b
MD5 e037118e57cfb2acc119cc5fecfa64b4
BLAKE2b-256 3bea515a82fc65c8e7eb537a46a23c01464d8d7ed0f21a3d98b91f43f6194b5f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page