Skip to content

Commit

Permalink
Merge branch 'main' into docs/HadilO/onboarding
Browse files Browse the repository at this point in the history
  • Loading branch information
carynbear authored Jul 10, 2024
2 parents 344301d + 90523e3 commit 84551cc
Show file tree
Hide file tree
Showing 15 changed files with 79 additions and 71 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/python-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.10', '3.11']
os: [ubuntu-latest, macOS-latest] #,windows-latest]
python-version: ['3.10'] #3.11
os: [ubuntu-latest] #, macOS-latest] #,windows-latest]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -24,12 +24,12 @@ jobs:
- name: Setup PDM
uses: pdm-project/[email protected]
with:
version: 2.10.4
version: 2.15.4
cache: true

- name: Install dependencies
run: |
pdm install -d -G tensorflow -G rebound
pdm install -G all
- name: Analysing the code with pylint
run: |
pdm run pylint $(git ls-files '*.py')
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
pyenv shell 3.10.14 #use the newly installed version
```

Check your installation by running `which python` which should output something along the lines of:
Check your installation by running `which python`. Output should be along the lines of:
- for mise: `/Users/[user]/.local/share/mise/installs/python/3.10.14/bin/python`

- for pyenv: `/Users/[user]/.pyenv/shims/python`
Expand Down
100 changes: 53 additions & 47 deletions demos/systems/hot_dino.ipynb

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions demos/systems/kuramoto_demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@
}
],
"source": [
"plot([x], legend_labels=[\"IND\"], max_oscillators=3, title=\"InD\", max_lines=2, phase_dynamics=True)\n",
"plot([x], labels=[\"IND\"], max_oscillators=3, title=\"InD\", max_lines=2, phase_dynamics=True)\n",
"\n",
"plot([x], legend_labels=[\"IND\"], max_oscillators=3, title=\"InD\", max_lines=2, phase_dynamics=False)\n",
"plot([x], labels=[\"IND\"], max_oscillators=3, title=\"InD\", max_lines=2, phase_dynamics=False)\n",
"# plot([y], max_oscillators=3, title=\"OOD\")"
]
},
Expand Down Expand Up @@ -126,7 +126,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.14"
"version": "3.10.11"
}
},
"nbformat": 4,
Expand Down
10 changes: 6 additions & 4 deletions src/dynadojo/baselines/dnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import time

from ..abstractions import AbstractAlgorithm

import logging


class TorchBaseClass(AbstractAlgorithm, torch.nn.Module):
Expand All @@ -33,7 +33,8 @@ def __init__(
torch.manual_seed(seed)

self.device = device or "cuda" if torch.cuda.is_available() else "mps" if torch.backends.mps.is_available() else "cpu"
print(f"Using device: {self.device}")
logging.info(f"Using device: {self.device}")
# print(f"Using device: {self.device}")
# self.model = self.create_model()
self.criterion = torch.nn.MSELoss()

Expand Down Expand Up @@ -90,7 +91,7 @@ def fit(self, x: np.ndarray,
losses = []
self.train()
training_start_time = time.time()
print(f'Dataloader length: {len(dataloader)}')
# print(f'Dataloader length: {len(dataloader)}')
for epoch in range(epochs):
self.train()
epoch_loss = 0
Expand Down Expand Up @@ -170,8 +171,9 @@ class DNN(TorchBaseClass):
def __init__(self,
embed_dim,
timesteps,
max_control_cost,
**kwargs):
super().__init__(embed_dim, timesteps, **kwargs)
super().__init__(embed_dim, timesteps, max_control_cost, **kwargs)
self.model = torch.nn.Sequential(
torch.nn.Linear(self.embed_dim, embed_dim*10),
torch.nn.ReLU(),
Expand Down
2 changes: 1 addition & 1 deletion src/dynadojo/systems/ctln.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def dynamics(t, state):

def calc_error(self, x, y) -> float:
error = x - y
return np.mean(error ** 2) / self.embed_dim
return np.mean(error ** 2)

def calc_control_cost(self, control: np.ndarray) -> float:
return np.linalg.norm(control, axis=(1, 2), ord=2)
2 changes: 1 addition & 1 deletion src/dynadojo/systems/kuramoto.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def solve(t, x0, U):

def calc_error(self, x, y) -> float:
error = x - y
return np.mean(error ** 2) / self.latent_dim
return np.mean(error ** 2)

def calc_control_cost(self, control: np.ndarray) -> float:
return np.linalg.norm(control, axis=(1, 2), ord=2)
Expand Down
2 changes: 1 addition & 1 deletion src/dynadojo/systems/lv/competitive.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def dynamics(t, X, u):

def calc_error(self, x, y) -> float:
error = x - y
return np.mean(error ** 2) / self.latent_dim
return np.mean(error ** 2)

def calc_control_cost(self, control: np.ndarray) -> float:
return np.linalg.norm(control, axis=(1, 2), ord=2)
Expand Down
2 changes: 1 addition & 1 deletion src/dynadojo/systems/lv/prey_predator.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def dynamics(t, X, u):

def calc_error(self, x, y) -> float:
error = x - y
return np.mean(error ** 2) / self.latent_dim
return np.mean(error ** 2)

def calc_control_cost(self, control: np.ndarray) -> float:
return np.linalg.norm(control, axis=(1, 2), ord=2)
Expand Down
2 changes: 1 addition & 1 deletion src/dynadojo/systems/opinion/media_bias.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def __init__(self, latent_dim=31, embed_dim=31,
self.config.add_model_parameter("gamma_media", bias_media)

def create_model(self, x0):
self.model = op.AlgorithmicBiasMediaModel(self.g)
self.model = op.AlgorithmicBiasModel(self.g)
self.model.set_initial_status(self.config)
self.model.status = x0
self.model.initial_status = x0
2 changes: 1 addition & 1 deletion src/dynadojo/systems/utils/epidemic.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def dynamics(x0):

def calc_error(self, x, y) -> float:
error = x - y
return np.mean(error ** 2) / self.latent_dim
return np.mean(error ** 2)

def calc_control_cost(self, control: np.ndarray) -> float:
return np.linalg.norm(control, axis=(1, 2), ord=2)
Expand Down
2 changes: 1 addition & 1 deletion src/dynadojo/systems/utils/fbsnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def make_data(self, init_conds: np.ndarray, control: np.ndarray, timesteps: int,

def calc_error(self, x, y) -> float:
error = x - y
return np.mean(error ** 2) / self.latent_dim
return np.mean(error ** 2)

def calc_control_cost(self, control: np.ndarray) -> float:
return np.linalg.norm(control, axis=(1, 2), ord=2)
Expand Down
2 changes: 1 addition & 1 deletion src/dynadojo/systems/utils/opinion.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def dynamics(x0):

def calc_error(self, x, y) -> float:
error = x - y
return np.mean(error ** 2) / self.latent_dim
return np.mean(error ** 2)

def calc_control_cost(self, control: np.ndarray) -> float:
return np.linalg.norm(control, axis=(1, 2), ord=2)
2 changes: 1 addition & 1 deletion src/dynadojo/systems/utils/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def make_init_conds(self, n: int, in_dist=True) -> np.ndarray:
def calc_error(self, x, y) -> float:
"""Returns the MSE error normalized by the embedded dimension."""
error = x - y
return np.mean(error ** 2) / self.embed_dim
return np.mean(error ** 2)

def calc_control_cost(self, control: np.ndarray) -> float:
"""Calculates the L2 norm / dimension of every vector in the control"""
Expand Down
6 changes: 3 additions & 3 deletions tests/test_deterministic.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
# baselines
from dynadojo.baselines.aug_ode import AugODE
from dynadojo.baselines.cnn import CNN
from dynadojo.baselines.dmd import DMD
# from dynadojo.baselines.dmd import DMD
from dynadojo.baselines.dnn import DNN
from dynadojo.baselines.ode import ODE
# from dynadojo.baselines.sindy import SINDy

ALL_BASELINES = [
# AugODE,
# CNN,
DMD,
# DMD,
DNN,
# ODE,
# SINDy
Expand Down Expand Up @@ -157,7 +157,7 @@ def test_with_trials(self, algo):
algo_kwargs=None)
cols = ['trial', 'latent_dim', 'embed_dim', 'timesteps', 'n', 'error', 'ood_error', 'total_cost',
'system_seed', 'algo_seed']
df1 = df1[cols]
df1 = df1[cols].loc[df2['trial'] == 1]
df2 = df2[cols].loc[df2['trial'] == 1]
self.assertEqual(df1, df2)

Expand Down

0 comments on commit 84551cc

Please sign in to comment.