Metadata-Version: 2.4
Name: caskade
Version: 0.8.3
Summary: Package for building scientific simulators, with dynamic arguments arranged in a directed acyclic graph.
Project-URL: Homepage, https://github.com/ConnorStoneAstro/caskade
Project-URL: Documentation, https://github.com/ConnorStoneAstro/caskade
Project-URL: Repository, https://github.com/ConnorStoneAstro/caskade
Project-URL: Issues, https://github.com/ConnorStoneAstro/caskade/issues
Author-email: Connor Stone <connorstone628@gmail.com>, Alexandre Adam <alexandre.adam@mila.quebec>
License: MIT License
        
        Copyright (c) 2024 Connor Stone, PhD
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: DAG,caskade,differentiable programming,pytorch,scientific python
Classifier: Development Status :: 1 - Planning
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.9
Requires-Dist: torch
Provides-Extra: dev
Requires-Dist: graphviz<1,>=0.17; extra == 'dev'
Requires-Dist: h5py<4,>=3.11; extra == 'dev'
Requires-Dist: pre-commit<4,>=3.6; extra == 'dev'
Requires-Dist: pytest-cov<5,>=4.1; extra == 'dev'
Requires-Dist: pytest-mock<4,>=3.12; extra == 'dev'
Requires-Dist: pytest<9,>=8.0; extra == 'dev'
Description-Content-Type: text/markdown

# caskade

[![CI](https://github.com/ConnorStoneAstro/caskade/actions/workflows/ci.yml/badge.svg)](https://github.com/ConnorStoneAstro/caskade/actions/workflows/ci.yml)
[![CD](https://github.com/ConnorStoneAstro/caskade/actions/workflows/cd.yml/badge.svg)](https://github.com/ConnorStoneAstro/caskade/actions/workflows/cd.yml)
[![codecov](https://codecov.io/gh/ConnorStoneAstro/caskade/graph/badge.svg?token=7YAEJJZ4GM)](https://codecov.io/gh/ConnorStoneAstro/caskade)
[![PyPI - Version](https://img.shields.io/pypi/v/caskade)](https://pypi.org/project/caskade/)
[![Documentation Status](https://readthedocs.org/projects/caskade/badge/?version=latest)](https://caskade.readthedocs.io/en/latest/?badge=latest)

Build scientific simulators, treating them as a directed acyclic graph. Handles
argument passing for complex nested simulators.

## Install

``` bash
pip install caskade
```

## Usage

Make a `Module` object which may have some `Param`s. Define a `forward` method
using the decorator.

``` python
from caskade import Module, Param, forward

class MySim(Module):
    def __init__(self, a, b=None):
        super().__init__()
        self.a = a
        self.b = Param("b", b)

    @forward
    def myfun(self, x, b=None):
        return x + self.a + b
```

We may now create instances of the simulator and pass the dynamic parameters.

``` python
import torch

sim = MySim(1.0)

params = [torch.tensor(2.0)]

print(sim.myfun(3.0, params=params))
```

Which will print `6` by automatically filling `b` with the value from `params`.

### Why do this?

The above example is not very impressive, the real power comes from the fact
that `Module` objects can be nested arbitrarily making a much more complicated
analysis graph. Further, the `Param` objects can be linked or have other complex
relationships. All of the complexity of the nested structure and argument
passing is abstracted away so that at the top one need only pass a list of
tensors for each parameter, a single large 1d tensor, or a dictionary with the
same structure as the graph.

## Documentation

The `caskade` interface has lots of flexibility, check out the
[docs](https://caskade.readthedocs.io) to learn more. For a quick start, jump
right to the [Jupyter notebook
tutorial](https://caskade.readthedocs.io/en/latest/notebooks/BeginnersGuide.html)!