Implements Refactoring in Player Class and Initial Working Version
This commit is contained in:
47
diceplayer/shared/config/player_config.py
Normal file
47
diceplayer/shared/config/player_config.py
Normal file
@@ -0,0 +1,47 @@
|
||||
from diceplayer.shared.utils.dataclass_protocol import Dataclass
|
||||
from diceplayer.shared.config.gaussian_config import GaussianDTO
|
||||
from diceplayer.shared.config.dice_config import DiceConfig
|
||||
|
||||
from dataclasses import dataclass
|
||||
from dacite import from_dict
|
||||
|
||||
|
||||
@dataclass
|
||||
class PlayerConfig(Dataclass):
|
||||
"""
|
||||
Data Transfer Object for the player configuration.
|
||||
"""
|
||||
opt: bool
|
||||
maxcyc: int
|
||||
nprocs: int
|
||||
ncores: int
|
||||
|
||||
dice: DiceConfig
|
||||
gaussian: GaussianDTO
|
||||
|
||||
mem: int = None
|
||||
switchcyc: int = 3
|
||||
qmprog: str = 'g16'
|
||||
altsteps: int = 20000
|
||||
simulation_dir = 'simfiles'
|
||||
|
||||
def __post_init__(self):
|
||||
MIN_STEP = 20000
|
||||
# altsteps value is always the nearest multiple of 1000
|
||||
self.altsteps = round(max(MIN_STEP, self.altsteps) / 1000) * 1000
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, param: dict):
|
||||
if param['dice'] is None:
|
||||
raise ValueError(
|
||||
"Error: 'dice' keyword not specified in config file."
|
||||
)
|
||||
param['dice'] = DiceConfig.from_dict(param['dice'])
|
||||
|
||||
if param['gaussian'] is None:
|
||||
raise ValueError(
|
||||
"Error: 'gaussian' keyword not specified in config file."
|
||||
)
|
||||
param['gaussian'] = GaussianDTO.from_dict(param['gaussian'])
|
||||
|
||||
return from_dict(PlayerConfig, param)
|
||||
Reference in New Issue
Block a user