Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Move to new calculator API #517

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c94cc30
example calculator use
SamTov Apr 13, 2022
3061844
get new api working for project
SamTov Apr 13, 2022
4d7caba
update
SamTov May 31, 2022
b129791
update data saving
SamTov Jun 3, 2022
dff0abf
correct indexing for the value selection in GK
SamTov Jun 14, 2022
6c38737
test IC and update tests for new data
SamTov Jun 14, 2022
01e00cb
fix data availability checks
SamTov Jun 21, 2022
0998894
move data checking to parent class
SamTov Jun 21, 2022
25809b4
resolve data return.
SamTov Jun 22, 2022
c1f5cd9
move most of SQL checking to experiment class.
SamTov Jun 22, 2022
be5377c
try to debug
SamTov Jun 22, 2022
37f83c1
Merge remote-tracking branch 'origin/SamTov_Calculator_data_move' int…
SamTov Jun 23, 2022
b82bf3a
Identify issue with data loading and fix.
SamTov Jun 24, 2022
c144bbb
fix test
SamTov Jun 24, 2022
4876125
Merge remote-tracking branch 'origin/SamTov_IC_Patch' into SamTov_Cal…
SamTov Jun 24, 2022
4bb655d
fix plotting and move out of calculator
SamTov Jun 24, 2022
2e125cb
remove args dataclass
SamTov Jun 24, 2022
55813e7
move ADF code over to new API
SamTov Jun 24, 2022
533cc95
update RDF and coordination numbers
SamTov Jun 24, 2022
31f488d
move rdf stuff to new api
SamTov Jun 26, 2022
45f1679
Check KB and POMF tests
SamTov Jun 27, 2022
3af2d1c
update doc string
SamTov Jul 4, 2022
c383832
more updates
SamTov Jul 4, 2022
9197394
Merge branch 'main' into SamTov_Calculator_data_move
SamTov Jul 4, 2022
f80944e
Merge branch 'SamTov_Calculator_data_move' of https://github.com/zinc…
SamTov Jul 5, 2022
b13bcc1
update unnavailable calcs.
SamTov Aug 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions .github/dependabot.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ def test_project(traj_file, true_values, tmp_path):
project.add_experiment(
"NaCl", simulation_data=traj_file, timestep=0.002, temperature=1400
)

computation = project.run.AngularDistributionFunction(plot=False)
calculator = mds.calculators.AngularDistributionFunction(plot=False)
computation = project.execute_operation(calculator)

for item in computation["NaCl"].data_dict:
computation["NaCl"].data_dict[item].pop("max_peak")
Expand Down
6 changes: 4 additions & 2 deletions CI/integration_tests/calculators/test_coordination_numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ def test_project(traj_file, true_values, tmp_path):
"NaCl", simulation_data=traj_file, timestep=0.002, temperature=1400
)

computation = project.run.CoordinationNumbers(
savgol_order=3, savgol_window_length=111, plot=False
computation = project.execute_operation(
mds.calculators.CoordinationNumbers(
savgol_order=3, savgol_window_length=111, plot=False
)
)

data_dict = computation["NaCl"]["Na_Cl"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,12 @@ def test_calculator(tmp_path):
data = TrajectoryChunkData(species_list=[species], chunk_size=n_step)
data.add_data(pos, 0, species.name, pos_prop.name)
proc = ScriptInput(data=data, metadata=metadata, name="test_name")
exp.add_data(proc)
exp.add_data(proc, update_with_pubchempy=False)

res = exp.run.EinsteinDiffusionCoefficients(
calculator = mds.calculators.EinsteinDiffusionCoefficients(
plot=False, correlation_time=1, data_range=msd_range
)[species.name]
)
res = exp.execute_operation(calculator)[species.name]

time_should_be = time_step * np.arange(0, msd_range) * units.time
diff_coeff_should_be = diff_coeff * units.length**2 / units.time
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
from zinchub import DataHub

import mdsuite as mds
from mdsuite.calculators.einstein_distinct_diffusion_coefficients import (
EinsteinDistinctDiffusionCoefficients,
)


@pytest.fixture(scope="session")
Expand Down Expand Up @@ -68,8 +71,10 @@ def test_eddc_project(traj_file, true_values, tmp_path):
"NaCl", simulation_data=traj_file, timestep=0.002, temperature=1400
)

project.run.EinsteinDistinctDiffusionCoefficients(
plot=False, data_range=300, correlation_time=100
project.execute_operation(
EinsteinDistinctDiffusionCoefficients(
plot=False, data_range=300, correlation_time=300
)
)

# data_dict = project.load.EinsteinDistinctDiffusionCoefficients()[0].data_dict
Expand Down Expand Up @@ -97,8 +102,10 @@ def test_eddc_experiment(traj_file, true_values, tmp_path):
"NaCl", simulation_data=traj_file, timestep=0.002, temperature=1400
)

project.experiments["NaCl"].run.EinsteinDiffusionCoefficients(
plot=False, data_range=300, correlation_time=100
project.experiments["NaCl"].execute_operation(
EinsteinDistinctDiffusionCoefficients(
plot=False, data_range=300, correlation_time=300
)
)

# data_dict = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
from zinchub import DataHub

import mdsuite as mds
from mdsuite.calculators.einstein_helfand_ionic_conductivity import (
EinsteinHelfandIonicConductivity,
)


@pytest.fixture(scope="session")
Expand Down Expand Up @@ -67,6 +70,6 @@ def test_project(traj_file, true_values, tmp_path):
"NaCl", simulation_data=traj_file, timestep=0.002, temperature=1400
)

# computation = project.run.EinsteinHelfandIonicConductivity(plot=False)
_ = project.execute_operation(EinsteinHelfandIonicConductivity(plot=False))

# assertDeepAlmostEqual(computation["NaCl"].data_dict, true_values, decimal=-6)
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
from zinchub import DataHub

import mdsuite as mds
from mdsuite.calculators.green_kubo_distinct_diffusion_coefficients import (
GreenKuboDistinctDiffusionCoefficients,
)


@pytest.fixture(scope="session")
Expand Down Expand Up @@ -64,7 +67,9 @@ def test_project(traj_file, true_values, tmp_path):
"NaCl", simulation_data=traj_file, timestep=0.002, temperature=1400
)

project.run.GreenKuboDistinctDiffusionCoefficients(plot=False, correlation_time=100)
project.execute_operation(
GreenKuboDistinctDiffusionCoefficients(plot=False, correlation_time=300)
)

# data_dict = project.load.GreenKuboDistinctDiffusionCoefficients()[0].data_dict
#
Expand All @@ -91,8 +96,8 @@ def test_experiment(traj_file, true_values, tmp_path):
"NaCl", simulation_data=traj_file, timestep=0.002, temperature=1400
)

project.experiments["NaCl"].run.GreenKuboDistinctDiffusionCoefficients(
plot=False, correlation_time=100
project.experiments["NaCl"].execute_operation(
GreenKuboDistinctDiffusionCoefficients(plot=False, correlation_time=300)
)

# data_dict = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from zinchub import DataHub

import mdsuite as mds
from mdsuite.calculators.kirkwood_buff_integrals import KirkwoodBuffIntegral
from mdsuite.utils.testing import assertDeepAlmostEqual


Expand Down Expand Up @@ -63,8 +64,8 @@ def test_project(traj_file, true_values, tmp_path):
"NaCl", simulation_data=traj_file, timestep=0.002, temperature=1400
)

computation = project.run.KirkwoodBuffIntegral(
plot=False, savgol_window_length=111, savgol_order=3
computation = project.execute_operation(
KirkwoodBuffIntegral(plot=False, savgol_window_length=111, savgol_order=3)
)

assertDeepAlmostEqual(computation["NaCl"].data_dict, true_values, decimal=1)
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from zinchub import DataHub

import mdsuite as mds
from mdsuite.calculators import PotentialOfMeanForce
from mdsuite.utils.testing import assertDeepAlmostEqual


Expand Down Expand Up @@ -63,8 +64,8 @@ def test_project(traj_file, true_values, tmp_path):
"NaCl", simulation_data=traj_file, timestep=0.002, temperature=1400
)

computation = project.run.PotentialOfMeanForce(
plot=False, savgol_window_length=111, savgol_order=3
computation = project.execute_operation(
PotentialOfMeanForce(plot=False, savgol_window_length=111, savgol_order=3)
)

assertDeepAlmostEqual(computation["NaCl"].data_dict, true_values, decimal=0)
Expand All @@ -78,8 +79,8 @@ def test_experiment(traj_file, true_values, tmp_path):
"NaCl", simulation_data=traj_file, timestep=0.002, temperature=1400
)

computation = project.experiments["NaCl"].run.PotentialOfMeanForce(
plot=False, savgol_window_length=111, savgol_order=3
computation = project.experiments["NaCl"].execute_operation(
PotentialOfMeanForce(plot=False, savgol_window_length=111, savgol_order=3)
)

assertDeepAlmostEqual(computation.data_dict, true_values, decimal=0)
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ def test_project(traj_file, true_values, tmp_path):
"NaCl", simulation_data=traj_file, timestep=0.002, temperature=1400
)

computation = project.run.RadialDistributionFunction(plot=False)
computation = project.execute_operation(
mds.calculators.RadialDistributionFunction(plot=False)
)

assertDeepAlmostEqual(computation["NaCl"].data_dict, true_values, decimal=1)

Expand All @@ -76,7 +78,9 @@ def test_experiment(traj_file, true_values, tmp_path):
"NaCl", simulation_data=traj_file, timestep=0.002, temperature=1400
)

computation = project.experiments.NaCl.run.RadialDistributionFunction(plot=False)
computation = project.experiments.NaCl.execute_operation(
mds.calculators.RadialDistributionFunction(plot=False)
)

assertDeepAlmostEqual(computation.data_dict, true_values, decimal=1)

Expand All @@ -88,12 +92,14 @@ def test_computation_parameter(traj_file, true_values, tmp_path):
"NaCl", simulation_data=traj_file, timestep=0.002, temperature=1400
)

computation = project.experiments.NaCl.run.RadialDistributionFunction(
plot=False,
number_of_bins=50,
cutoff=5,
number_of_configurations=150,
species=["Na"],
computation = project.experiments.NaCl.execute_operation(
mds.calculators.RadialDistributionFunction(
plot=False,
number_of_bins=50,
cutoff=5,
number_of_configurations=150,
species=["Na"],
)
)

assert computation.computation_parameter["number_of_bins"] == 50
Expand Down
7 changes: 5 additions & 2 deletions CI/unit_tests/database/test_experiment_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,5 +225,8 @@ def test_experiment_units(tmp_path):

project_2 = mds.Project()

assert project_2.experiments["Exp01"].units == si
assert project_2.experiments["Exp02"].units == custom_units
for key, val in project_2.experiments["Exp01"].units.items():
assert val == getattr(si, key)

for key, val in project_2.experiments["Exp02"].units.items():
assert val == getattr(custom_units, key)
43 changes: 43 additions & 0 deletions CI/unit_tests/utils/test_helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""
MDSuite: A Zincwarecode package.

License
-------
This program and the accompanying materials are made available under the terms
of the Eclipse Public License v2.0 which accompanies this distribution, and is
available at https://www.eclipse.org/legal/epl-v20.html

SPDX-License-Identifier: EPL-2.0

Copyright Contributors to the Zincwarecode Project.

Contact Information
-------------------
email: [email protected]
github: https://github.com/zincware
web: https://zincwarecode.com/

Citation
--------
If you use this module please cite us with:

Summary
-------
Test the helper functions module.
"""
from mdsuite.utils.helpers import generate_dataclass


class TestHelpers:
"""
Test all functions in the helpers file.
"""

def test_generate_dataclass(self):
"""
Test the generate dataclass function.
"""
class_1 = generate_dataclass(par_a=5, par_b="hello", par_c=None)
assert class_1.par_a == 5
assert class_1.par_b == "hello"
assert class_1.par_c is None
4 changes: 2 additions & 2 deletions CI/unit_tests/utils/test_scaling_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ def test_linearithmic_scaling_function(self):
"""
# Assert simple multiplication
data = linearithmic_scale_function(10, 1)
self.assertAlmostEqual(data, 23.02585092994046, 5)
self.assertEqual(data, 23.02585092994046)

# Assert scaled multiplication
data = linearithmic_scale_function(10, 3)
self.assertAlmostEqual(data, 69.07755278982138, 5)
self.assertEqual(data, 69.07755278982138)

# Assert array values
data = linearithmic_scale_function(np.array([5, 10, 20]), 2)
Expand Down
Loading