Coder Social home page Coder Social logo

adacs-australia / rombus Goto Github PK

View Code? Open in Web Editor NEW
1.0 4.0 5.0 562 KB

For full documentation, see:

Home Page: https://rombus.readthedocs.io/en/latest/

License: MIT License

Makefile 1.67% Python 98.33%
model-order-reduction reduced-basis reduced-order-models

rombus's Introduction

Rombus: Helps you qucikly and easily compute slow and complex models

Rombus is a tool for building reduced order models (ROMs): matrix representations of arbitrary models which can be rapidly and easily computed for arbitrary parameter sets.

Building a ROM with Rombus is easy. All you need to do is install it like so:

$ pip install rombus

define your model like this (in this trivial case, a file named my_model.py specifying a simple second-order polynomial):

from numpy import ndarray, polyval, linspace
from rombus.model import RombusModel
from typing import NamedTuple


class Model(RombusModel):
    """Class for creating a ROM for the function y(x)=a2*x^2+a1*x+a0"""

    coordinate.set("x", 0.0, 10.0, 11, label="$x$")

    ordinate.set("y", label="$y(x)$")

    params.add("a0", -10, 10)
    params.add("a1", -10, 10)
    params.add("a2", -10, 10)

    def compute(self, p: NamedTuple, x: ndarray) -> ndarray:
        """Compute the model for a given parameter set."""
        return polyval([p.a2, p.a1, p.a0], x)

and specify a set of points (in this case, the file my_model_samples.py) to build your ROM from:

-10, -10,-10
-10,  10,-10
-10, -10, 10
-10,  10, 10
 10, -10,-10
 10,  10,-10
 10, -10, 10
 10,  10, 10

You build your ROM like this:

$ rombus build my_model:Model my_model_samples.csv

This produces an HDF5 file named my_model.hdf5. You can then use your new ROM in your Python projects like this:

from rombus.rom import ReducedOrderModel

ROM = ReducedOrderModel.from_file('my_model.hdf5')
sample = ROM.model.sample({"a0":0,"a1":0,"a2":1})
model_ROM = ROM.evaluate(sample)
for x, y in zip(ROM.model.domain,model_ROM):
    print(f"{x:5.2f} {y:6.2f}")

which generates the output:

 0.00   0.00
 1.00   1.00
 2.00   4.00
 3.00   9.00
 4.00  16.00
 5.00  25.00
 6.00  36.00
 7.00  49.00
 8.00  64.00
 9.00  81.00
10.00 100.00

rombus's People

Contributors

avivajpeyi avatar gbpoole avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

rombus's Issues

Struggling to run ROMBUS in parallel.

Hi,

As the title suggests, I am struggling to run ROMBUS in parallel. Using the PhenomP.py model and PhenomP_samples.csv samples in rombus/models/, I run the following command on the head node of the OzStar Ngarrgu Tindebeek (NT) cluster:

mpirun rombus build PhenomP:Model PhenomP_samples.csv

And get the following error when ROMBUS runs the greedy algorithm to fill the reduced basis:

File "/home/abaker/.conda/envs/fresh-rombus/lib/python3.11/site-packages/rombus/cli.py", line 99, in build
    ROM = ReducedOrderModel(model_loaded, samples).build(do_step=do_step)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/abaker/.conda/envs/fresh-rombus/lib/python3.11/site-packages/rombus/_core/log/log.py", line 253, in wrapper
    r = func(*args, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^
  File "/home/abaker/.conda/envs/fresh-rombus/lib/python3.11/site-packages/rombus/rom.py", line 113, in build
    self.reduced_basis = ReducedBasis().compute(
   File "/home/abaker/.conda/envs/fresh-rombus/lib/python3.11/site-packages/rombus/reduced_basis.py", line 114, in compute
    with log.progress(
  File "/home/abaker/.conda/envs/fresh-rombus/lib/python3.11/site-packages/rombus/_core/log/log.py", line 363, in __exit__
    self._exception_handler(exc_val)
File "/fred/oz209/abaker/.conda/envs/rombus/src/rombus/python/rombus/reduced_basis.py", line 151, in compute
    basis_index = self._convert_to_basis_index(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/fred/oz209/abaker/.conda/envs/rombus/src/rombus/python/rombus/reduced_basis.py", line 275, in _convert_to_basis_index
    idx_till_err_rank = np.sum([rank_count[i] for i in ranks_till_err_rank])
    
   IndexError: invalid index to scalar variable.

When instead requesting 16 CPUs on a single submit node and running the above command without mpirun, i.e. with the submit file

#!/bin/bash
#SBATCH --job-name=test_rombus
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=16
#SBATCH --time=0:30:00
#SBATCH --mem-per-cpu=4000
#SBATCH --output=pipe_submit.log

ml mamba && conda activate fresh-rombus

rombus build PhenomP:Model PhenomP_samples.csv

It completes successfully but appears to just run in serial based on the output in the log file. However, I get the following warning:

MPI startup(): PMI server not found. Please set I_MPI_PMI_LIBRARY variable if it is not a singleton case.

But I am not sure how to interpret this with respect to whether ROMBUS parallelised or not. Would anyone be able to help guide me in the right direction?

Thanks in advance!

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.