Skip to content

Commit

Permalink
call to tests now work from every folder, updated tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
daneschi committed Jul 10, 2023
1 parent f2b7a01 commit 6fcdd20
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 20 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/test_publish_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ jobs:
pip install -e .
- name: Run tests
run: |
it=100 python3 -m unittest linfa.tests.test_linfa.linfa_test_suite.trivial_example
it=100 python3 -m unittest linfa.tests.test_linfa.linfa_test_suite.highdim_example
it=100 python3 -m unittest linfa.tests.test_linfa.linfa_test_suite.rc_example
it=100 python3 -m unittest linfa.tests.test_linfa.linfa_test_suite.rcr_example
it=100 python3 -m unittest linfa.tests.test_linfa.linfa_test_suite.adaann_example
run: |
it=100 python3 -m unittest linfa.linfa_test_suite.trivial_example
it=100 python3 -m unittest linfa.linfa_test_suite.highdim_example
it=100 python3 -m unittest linfa.linfa_test_suite.rc_example
it=100 python3 -m unittest linfa.linfa_test_suite.rcr_example
it=100 python3 -m unittest linfa.linfa_test_suite.adaann_example
- name: Publish to PyPI
# if: startsWith(github.ref, 'refs/tags')
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@ The implementation of the lumped parameter network models (RC and RCR models) fo

To run the tests type
```sh
python -m unittest linfa.tests.test_linfa.linfa_test_suite.NAME_example
python -m unittest linfa.linfa_test_suite.NAME_example
```
where `NAME` need to be replaced by
* `trivial` for the trivial example (Ex 1).
* `highdim` for the high-dimensional example (Ex 2).
* `rc` for the RC model (Ex 3).
* `rcr` for the RCR model (Ex 4).
* `adaann` for the Friedman model example (Ex 5).
* `rcr_nofas_adaann_example` for the RCR model, combining NoFAS with adaptive annealing (AdaAnn)

At regular intervals set by the parameter `experiment.save_interval` LINFA writes a few results files. The sub-string `NAME` refers to the experiment name specified in the `experiment.name` variable, and `IT` indicates the iteration at which the file is written. The results files are

Expand Down Expand Up @@ -89,7 +90,7 @@ In addition you need to specify a list of options as discussed in the [documenta

### Tutorial

A (tutorial)[] is also available which will guide you through the definition of each of the quantities and function required by LINFA.
A step by step [tutorial](tutorial/TutorialwithPhys.ipynb) is also available which will guide you through the an inference problem for a ballistic simulation.

### Citation

Expand Down
2 changes: 1 addition & 1 deletion linfa/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from tests.test_linfa import linfa_test_suite
from linfa.tests.test_linfa import linfa_test_suite
2 changes: 1 addition & 1 deletion linfa/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from test_linfa import linfa_test_suite
from linfa.tests.test_linfa import linfa_test_suite
25 changes: 16 additions & 9 deletions linfa/tests/test_linfa.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import unittest
import os
import linfa
from linfa.run_experiment import experiment
from linfa.transform import Transformation
from linfa.nofas import Surrogate
Expand Down Expand Up @@ -77,7 +78,8 @@ def trivial_example(self):
exp.model = model

# Get data
model.data = np.loadtxt('./resource/data/data_trivial.txt')
res_path = os.path.abspath(os.path.join(os.path.dirname(linfa.__file__), os.pardir))
model.data = np.loadtxt(res_path + '/resource/data/data_trivial.txt')

# Define surrogate
exp.surrogate = Surrogate(exp.name, lambda x: model.solve_t(trsf.forward(x)), 2, 2,
Expand Down Expand Up @@ -196,7 +198,8 @@ def highdim_example(self):
exp.model = model

# Read data
model.data = np.loadtxt('./resource/data/data_highdim.txt')
res_path = os.path.abspath(os.path.join(os.path.dirname(linfa.__file__), os.pardir))
model.data = np.loadtxt(res_path + '/resource/data/data_highdim.txt')

# Define the surrogate
exp.surrogate = Surrogate(exp.name, lambda x: model.solve_t(trsf.forward(x)), model.input_num, model.output_num,
Expand Down Expand Up @@ -310,12 +313,13 @@ def rc_example(self):
# Define model
cycleTime = 1.07
totalCycles = 10
forcing = np.loadtxt('./resource/data/inlet.flow')
res_path = os.path.abspath(os.path.join(os.path.dirname(linfa.__file__), os.pardir))
forcing = np.loadtxt(res_path + '/resource/data/inlet.flow')
model = rcModel(cycleTime, totalCycles, forcing, device=exp.device) # RCR Model Defined
exp.model = model

# Read Data
model.data = np.loadtxt('./resource/data/data_rc.txt')
model.data = np.loadtxt(res_path + '/resource/data/data_rc.txt')

# Define surrogate model
exp.surrogate = Surrogate(exp.name, lambda x: model.solve_t(trsf.forward(x)), exp.input_size, 3,
Expand Down Expand Up @@ -430,12 +434,13 @@ def rcr_example(self):
# Define model
cycleTime = 1.07
totalCycles = 10
forcing = np.loadtxt('./resource/data/inlet.flow')
res_path = os.path.abspath(os.path.join(os.path.dirname(linfa.__file__), os.pardir))
forcing = np.loadtxt(res_path + '/resource/data/inlet.flow')
model = rcrModel(cycleTime, totalCycles, forcing, device=exp.device) # RCR Model Defined
exp.model = model

# Read data
model.data = np.loadtxt('./resource/data/data_rcr.txt')
model.data = np.loadtxt(res_path + '/resource/data/data_rcr.txt')

# Define surrogate
exp.surrogate = Surrogate(exp.name, lambda x: model.solve_t(trsf.forward(x)), exp.input_size, 3,
Expand Down Expand Up @@ -551,7 +556,8 @@ def adaann_example(self):
exp.device = torch.device('cuda:0' if torch.cuda.is_available() and not exp.no_cuda else 'cpu')

# Model Setting
data_set = np.loadtxt('./resource/data/D1000.csv',delimiter=',',skiprows=1)
res_path = os.path.abspath(os.path.join(os.path.dirname(linfa.__file__), os.pardir))
data_set = np.loadtxt(res_path + '/resource/data/D1000.csv',delimiter=',',skiprows=1)
data = torch.tensor(data_set).to(exp.device)

def log_density(params, d):
Expand Down Expand Up @@ -659,12 +665,13 @@ def rcr_nofas_adaann_example(run_nofas=True, run_adaann=False):
# Define model
cycleTime = 1.07
totalCycles = 10
forcing = np.loadtxt('./resource/data/inlet.flow')
res_path = os.path.abspath(os.path.join(os.path.dirname(linfa.__file__), os.pardir))
forcing = np.loadtxt(res_path + '/resource/data/inlet.flow')
model = rcrModel(cycleTime, totalCycles, forcing, device=exp.device) # RCR Model Defined
exp.model = model

# Read data
model.data = np.loadtxt('./resource/data/data_rcr.txt')
model.data = np.loadtxt(res_path + '/resource/data/data_rcr.txt')

# Define surrogate
exp.surrogate = Surrogate(exp.name, lambda x: model.solve_t(trsf.forward(x)), exp.input_size, 3,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "linfa_vi"
version = "1.1.4"
version = "1.1.5"
description = "A Python library for inference with normalizing flow and annealing"
readme = "README.md"
authors = [{ name = "resDesLab ", email = "daniele.schiavazzi@gmail.com" }]
Expand Down

0 comments on commit 6fcdd20

Please sign in to comment.