feat: add dice input generation and player routines for NVT/NPT simulations
This commit is contained in:
@@ -1,56 +1,62 @@
|
||||
from diceplayer.config.dice_config import DiceConfig
|
||||
from diceplayer.config.gaussian_config import GaussianConfig
|
||||
from diceplayer.config.player_config import PlayerConfig
|
||||
from diceplayer.config.player_config import PlayerConfig, RoutineType
|
||||
|
||||
import pytest
|
||||
|
||||
from typing import Any
|
||||
|
||||
def get_config_dict():
|
||||
return {
|
||||
"opt": True,
|
||||
"mem": 12,
|
||||
"maxcyc": 100,
|
||||
"nprocs": 4,
|
||||
"ncores": 4,
|
||||
"dice": {
|
||||
|
||||
class TestPlayerConfig:
|
||||
@pytest.fixture
|
||||
def dice_payload(self) -> dict[str, Any]:
|
||||
return {
|
||||
"ljname": "test",
|
||||
"outname": "test",
|
||||
"dens": 1.0,
|
||||
"nmol": [1],
|
||||
"nstep": [1, 1],
|
||||
},
|
||||
"gaussian": {
|
||||
}
|
||||
|
||||
@pytest.fixture
|
||||
def gaussian_payload(self) -> dict[str, Any]:
|
||||
return {
|
||||
"level": "test",
|
||||
"qmprog": "g16",
|
||||
"keywords": "test",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
class TestPlayerConfig:
|
||||
@pytest.fixture
|
||||
def dice_config(self):
|
||||
return DiceConfig(
|
||||
ljname="test",
|
||||
outname="test",
|
||||
dens=1.0,
|
||||
nmol=[1],
|
||||
nstep=[1, 1],
|
||||
)
|
||||
}
|
||||
|
||||
@pytest.fixture
|
||||
def gaussian_config(self):
|
||||
return GaussianConfig(
|
||||
level="test",
|
||||
qmprog="g16",
|
||||
keywords="test",
|
||||
)
|
||||
def player_payload(
|
||||
self, dice_payload: dict[str, Any], gaussian_payload: dict[str, Any]
|
||||
) -> dict[str, Any]:
|
||||
return {
|
||||
"type": "both",
|
||||
"mem": 12,
|
||||
"max_cyc": 100,
|
||||
"switch_cyc": 50,
|
||||
"nprocs": 4,
|
||||
"ncores": 4,
|
||||
"dice": dice_payload,
|
||||
"gaussian": gaussian_payload,
|
||||
}
|
||||
|
||||
def test_class_instantiation(self, dice_config, gaussian_config):
|
||||
@pytest.fixture
|
||||
def dice_config(self, dice_payload: dict[str, Any]) -> DiceConfig:
|
||||
return DiceConfig.model_validate(dice_payload)
|
||||
|
||||
@pytest.fixture
|
||||
def gaussian_config(self, gaussian_payload: dict[str, Any]):
|
||||
return GaussianConfig.model_validate(gaussian_payload)
|
||||
|
||||
def test_class_instantiation(
|
||||
self, dice_config: DiceConfig, gaussian_config: GaussianConfig
|
||||
):
|
||||
player_dto = PlayerConfig(
|
||||
opt=True,
|
||||
type=RoutineType.BOTH,
|
||||
mem=12,
|
||||
maxcyc=100,
|
||||
max_cyc=100,
|
||||
switch_cyc=50,
|
||||
nprocs=4,
|
||||
ncores=4,
|
||||
dice=dice_config,
|
||||
@@ -61,22 +67,25 @@ class TestPlayerConfig:
|
||||
assert isinstance(player_dto.dice, DiceConfig)
|
||||
assert isinstance(player_dto.gaussian, GaussianConfig)
|
||||
|
||||
def test_min_altsteps(self, dice_config, gaussian_config):
|
||||
def test_min_altsteps(
|
||||
self, dice_config: DiceConfig, gaussian_config: GaussianConfig
|
||||
):
|
||||
player_dto = PlayerConfig(
|
||||
opt=True,
|
||||
type=RoutineType.BOTH,
|
||||
mem=12,
|
||||
maxcyc=100,
|
||||
max_cyc=100,
|
||||
switch_cyc=50,
|
||||
nprocs=4,
|
||||
ncores=4,
|
||||
altsteps=100,
|
||||
altsteps=0,
|
||||
dice=dice_config,
|
||||
gaussian=gaussian_config,
|
||||
)
|
||||
|
||||
assert player_dto.altsteps == 20000
|
||||
|
||||
def test_from_dict(self):
|
||||
player_dto = PlayerConfig.model_validate(get_config_dict())
|
||||
def test_from_dict(self, player_payload: dict[str, Any]):
|
||||
player_dto = PlayerConfig.model_validate(player_payload)
|
||||
|
||||
assert isinstance(player_dto, PlayerConfig)
|
||||
assert isinstance(player_dto.dice, DiceConfig)
|
||||
|
||||
0
tests/dice/__init__.py
Normal file
0
tests/dice/__init__.py
Normal file
65
tests/dice/test_dice_input.py
Normal file
65
tests/dice/test_dice_input.py
Normal file
@@ -0,0 +1,65 @@
|
||||
from pathlib import Path
|
||||
|
||||
from diceplayer.config import PlayerConfig
|
||||
from diceplayer.dice.dice_input import NVTEqConfig, NVTTerConfig, NPTTerConfig, NPTEqConfig
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
class TestDiceInput:
|
||||
@pytest.fixture
|
||||
def player_config(self) -> PlayerConfig:
|
||||
return PlayerConfig.model_validate(
|
||||
{
|
||||
"type": "both",
|
||||
"mem": 12,
|
||||
"max_cyc": 100,
|
||||
"switch_cyc": 50,
|
||||
"nprocs": 4,
|
||||
"ncores": 4,
|
||||
"dice": {
|
||||
"ljname": "test",
|
||||
"outname": "test",
|
||||
"dens": 1.0,
|
||||
"nmol": [1],
|
||||
"nstep": [1, 1],
|
||||
},
|
||||
"gaussian": {
|
||||
"level": "test",
|
||||
"qmprog": "g16",
|
||||
"keywords": "test",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
def test_generate_nvt_ter_input(self, player_config: PlayerConfig):
|
||||
dice_input = NVTTerConfig.from_config(player_config)
|
||||
|
||||
assert isinstance(dice_input, NVTTerConfig)
|
||||
|
||||
def test_generate_nvt_eq_input(self, player_config: PlayerConfig):
|
||||
dice_input = NVTEqConfig.from_config(player_config)
|
||||
|
||||
assert isinstance(dice_input, NVTEqConfig)
|
||||
|
||||
def test_generate_npt_ter_input(self, player_config: PlayerConfig):
|
||||
dice_input = NPTTerConfig.from_config(player_config)
|
||||
|
||||
assert isinstance(dice_input, NPTTerConfig)
|
||||
|
||||
def test_generate_npt_eq_input(self, player_config: PlayerConfig):
|
||||
dice_input = NPTEqConfig.from_config(player_config)
|
||||
|
||||
assert isinstance(dice_input, NPTEqConfig)
|
||||
|
||||
def test_write_dice_config(self, player_config: PlayerConfig, tmp_path: Path):
|
||||
dice_input = NVTTerConfig.from_config(player_config)
|
||||
|
||||
output_file = tmp_path / "nvt_ter.inp"
|
||||
|
||||
with open(output_file, "w") as file:
|
||||
dice_input.write_dice_config(file)
|
||||
|
||||
assert output_file.exists()
|
||||
|
||||
print(output_file.read_text())
|
||||
@@ -12,9 +12,10 @@ class TestStateHandler:
|
||||
@pytest.fixture
|
||||
def player_config(self) -> PlayerConfig:
|
||||
return PlayerConfig(
|
||||
opt=True,
|
||||
type="both",
|
||||
mem=12,
|
||||
maxcyc=100,
|
||||
max_cyc=100,
|
||||
switch_cyc=50,
|
||||
nprocs=4,
|
||||
ncores=4,
|
||||
dice=DiceConfig(
|
||||
@@ -87,7 +88,7 @@ class TestStateHandler:
|
||||
|
||||
state_handler.save(state)
|
||||
|
||||
different_config = player_config.model_copy(update={"opt": False})
|
||||
different_config = player_config.model_copy(update={"max_cyc": 200})
|
||||
|
||||
retrieved_state = state_handler.get(different_config)
|
||||
|
||||
@@ -106,7 +107,7 @@ class TestStateHandler:
|
||||
|
||||
state_handler.save(state)
|
||||
|
||||
different_config = player_config.model_copy(update={"opt": False})
|
||||
different_config = player_config.model_copy(update={"max_cyc": 200})
|
||||
|
||||
retrieved_state = state_handler.get(different_config, force=True)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user