-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from fenfisdi/issue/11/update_unit_tests
Issue/11/update unit tests
- Loading branch information
Showing
18 changed files
with
608 additions
and
630 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[build-system] | ||
requires = ["setuptools", "wheel"] | ||
build-backend = "setuptools.build_meta:__legacy__" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
from typing import Any, List | ||
import pytest | ||
|
||
from numpy import pi | ||
from numpy.random import random | ||
|
||
from dinjo.model import StateVariable, Parameter | ||
from dinjo.optimizer import Optimizer | ||
from dinjo.predefined.physics import ModelOscillator | ||
|
||
|
||
@pytest.fixture(scope='session') | ||
def ho_state_vars(): | ||
# Harmonic Oscillator Initial Value Problem | ||
q = StateVariable( | ||
name='position', representation='q', initial_value=1.0 | ||
) | ||
p = StateVariable( | ||
name='momentum', representation='p', initial_value=0.0 | ||
) | ||
return [q, p] | ||
|
||
|
||
@pytest.fixture(scope='session') | ||
def ho_params(): | ||
# Define Paramters | ||
omega = Parameter( | ||
name='frequency', representation='w', initial_value=2 * pi, bounds=[4, 8] | ||
) | ||
return [omega] | ||
|
||
|
||
@pytest.fixture(scope='session') | ||
def t_span(): | ||
return [0, 1] | ||
|
||
|
||
@pytest.fixture(scope='session') | ||
def t_steps(): | ||
return 50 | ||
|
||
|
||
@pytest.fixture(scope='session') | ||
def model_oscillator(ho_state_vars, ho_params, t_span, t_steps): | ||
# Instantiate the IVP class with appropiate State Variables and Parameters | ||
return ModelOscillator( | ||
state_variables=ho_state_vars, | ||
parameters=ho_params, | ||
t_span=t_span, | ||
t_steps=t_steps | ||
) | ||
|
||
|
||
@pytest.fixture(scope='session') | ||
def oscillator_solution(model_oscillator: ModelOscillator): | ||
return model_oscillator.run_model() | ||
|
||
|
||
@pytest.fixture(scope='session') | ||
def ho_mock_values(oscillator_solution: Any, t_steps: List[float]): | ||
noise_factor = 0.3 | ||
return ( | ||
oscillator_solution.y[0] | ||
+ (2 * random(t_steps) - 1) * noise_factor | ||
) | ||
|
||
|
||
@pytest.fixture(scope='session') | ||
def ho_optimizer( | ||
model_oscillator: ModelOscillator, | ||
oscillator_solution: Any, | ||
ho_mock_values: List[float], | ||
ho_state_vars: List[StateVariable] | ||
): | ||
return Optimizer( | ||
model_oscillator, | ||
ho_state_vars[0], | ||
ho_mock_values, | ||
oscillator_solution.t | ||
) |
Empty file.
Oops, something went wrong.