Skip to content

adamryczkowski/StanTasq

Repository files navigation

Stan task scheduler

For the worker to work, it needs:

  1. Running backend storage server: NATS

  2. One or more workers running: taskiq worker

  3. A driver that requests the tasks (e.g. unit test)

NAT server

To get the NATS server running, install it with

curl -sf https://binaries.nats.dev/nats-io/nats-server/v2@latest | sh

Put the following configuration into a file, e.g. ~/.config/nats/nats-config.conf:

listen: 0.0.0.0:4222
authorization: {
    token: "szakal"
}
jetstream {
    # Jetstream storage location, limits and encryption
    store_dir: "/home/Adama-docs/nats"

    # 1GB
    max_memory_store: 1073741824

    # 10GB
    max_file_store: 10737418240
}

Obviously, the token should be a little more secure.

Then run the server with:

nats-server --config ~/.config/nats/nats-config.conf

Taskiq broker

Taskiq workers are driven by the taskiq command. To get it working, install the current repository with poetry install or pip install ..

Then enter its environment (e.g. poetry shell or . vevn/bin/activate).

Once there, a taskiq command will be available. To run a broker capable of running all the workers defined in the project, run:

worker StanTasq:broker

Broker will find the tasks, because each task is decorated with the @broker decorator, and loaded on project’s startup in init.py.

Taskiq driver

Simply run the tests/test_basic.py defined in the project.

TODO:

  1. Test serializable type that is a union of many: Union[ResultError, ResultFullSamples, ResultCovariances, ResultMainEffects, ResultRawMCMC, ResultRawPathfinder, ResultRawVB, ResultRawLaplace]. Use Multiple Pydantic Models with a Discriminated Union: https://blog.det.life/pydantic-for-experts-discriminated-unions-in-pydantic-v2-2d9ca965b22f

  2. Implement types that hold results, for each type of StanResultEngine, StanOutputScope and error type.

    1. If there is StanErrorType of SYNTAX_ERROR, COMPILE_ERROR or DATA_ERROR: the result will be of type ResultError.

    2. For StanOutputScope.RawOutput each element of StanResultEngine will have its own dedicated result type. Errors of type RUNTIME_ERROR will be stored in the object.

    3. For all other StanOutputScope types, the result will be one of: ResultFullSamples, ResultCovariances or ResultMainEffects. Errors of type RUNTIME_ERROR will be stored in the object.

  3. Test error handling in every stage of the task:

    1. reading in the model,

    2. compiling the model,

    3. testing if data fits the model,

    4. running the model

  4. Add functionality to search for the result in "AllTasks" based on the request cache.

  5. Test just test recipe.

  6. Implement serialization as the RAW scope.

  7. Rename serialized model files to have a proper extension. Bin? Obj? Zip?

  8. Consider code de-duplication between local test result and remote test result.

About

Tasq tasks doing Stan computation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages