Git Product home page Git Product logo

amisc's Introduction

Logo pdm-managed PyPI Python 3.11 Commits build docs tests Coverage Status Algorithm description

Efficient framework for building surrogates of multidisciplinary systems. Uses the adaptive multi-index stochastic collocation (AMISC) technique.

Installation

We highly recommend using pdm:

pip install --user pdm
cd <your-project>
pdm init
pdm add amisc

However, you can also install normally:

pip install amisc

To install from an editable local directory (e.g. for development), first fork the repo and then:

git clone https://github.com/<your-username>/amisc.git
pdm add -e ./amisc --dev  # or..
pip install -e ./amisc    # similarly

This way you can make changes to amisc locally while working on some other project for example. You can also quickly set up a dev environment with:

git clone https://github.com/<your-username>/amisc.git
cd amisc
pdm install  # reads pdm.lock and sets up an identical venv

Quickstart

import numpy as np

from amisc.system import SystemSurrogate, ComponentSpec
from amisc.rv import UniformRV

def fun1(x):
    return dict(y=x * np.sin(np.pi * x))

def fun2(x):
    return dict(y=1 / (1 + 25 * x ** 2))

x = UniformRV(0, 1, 'x')
y = UniformRV(0, 1, 'y')
z = UniformRV(0, 1, 'z')
model1 = ComponentSpec(fun1, exo_in=x, coupling_out=y)
model2 = ComponentSpec(fun2, coupling_in=y, coupling_out=z)

inputs = x
outputs = [y, z]
system = SystemSurrogate([model1, model2], inputs, outputs)
system.fit()

x_test = system.sample_inputs(10)
y_test = system.predict(x_test)

Contributing

See the contribution guidelines.

Citations

AMISC paper [1].

amisc's People

Contributors

eckelsjd avatar

Stargazers

 avatar

Watchers

 avatar  avatar

amisc's Issues

Clean up RV import

Expected Behavior

  • The load_variables() function loads BaseRV objects from a json spec file.
  • There are a lot of messy things going on here, such as specifying bounds twice for uniform variables, specifying the "id" of the variables twice, using the keyword "id" in the first place, etc.
  • Would also be good if these RV objects can specify "priors" and "posteriors" separately.
  • Make it more clear what the "nominal" value is.
  • Could also incorporate actual units checking with 3rd party libraries like pint.
  • I also wonder if BaseRV objects are implemented better anywhere else. Surely someone has tried an object-oriented approach like this before.

Clean up vectorization

New Behavior

  • Functions like SystemSurrogate.predict() and any __call__(x)-like function should utilize the concept of ufuncs in numpy. They should be written with only the "single-sample" use-case in mind where x.shape=(xdim,). Then they can be cast to a ufunc and automatically broadcast to any other shape (..., xdim) under the hood.
  • See this idea in the numpy documentation.
  • This would significantly simplify the logic and indexing in a lot of these functions.
  • This would also make these these functions more amenable to jax.grad auto-differentiation. Try to rewrite these methods to be as "pure" function-like as possible with no side-effects like array-mutation.

Clean up model wrapper requirements

Current Behavior

  • Model wrapper functions must follow a set of very specific rules in order to be compatible with the amisc framework.
  • For nearly all cases, these rules aren't restrictive of the types of models that can be used; it just makes it more difficult for the user to interact with amisc and can be a significant impediment to adoption.

Desired Behavior

  • The simple call signature y=fun(x), with x.shape = (xdim,) and y.shape = (ydim,) should be the only requirement.
  • Useful/general defaults should be set for everything else

Some example improvements

  • The ordering of the inputs in xdim should have an obvious default, with an option to specify an alternate ordering.
  • If the function is not universally broadcasting, it should be wrapped so that it is such.
  • The model fidelity alpha kwarg should be added by default if the user doesn't specify it.
  • The model should be allowed to return a variable number of things. Defaults should be set for which return items are one of the things used internally by amisc, i.e. y, files, cost. There should be an option for changing these defaults
  • Handling of output_dir should be improved and made more obvious. Should force this kwarg into the model if necessary, and remove the odd requirements about returning file names

I think this amounts to forcing an internal wrapper function around whatever callable model the user passes in. The user has all the freedom to write their function as they please, and the internal wrapper will manage linking it to the amisc framework. This can all be done within the ComponentSpec object, for example.

Multidisciplinary system derivatives

New behavior

  • Compute Jacobian of system-level outputs with respect to system-level inputs
  • Compute Hessian similarly
  • Handle both feedforward and feedback connections
  • Utilize auto-differentiation when possible (e.g. via jax)
  • Provide interface for custom derivative implementation at the BaseInterpolator level

Notes

  • This will probably involve looking into "unified derivatives"
  • See how OpenMDAO does it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.