No tolerance in ensemble parameters comparison
The current structure of mchammer
does not allow ensemble parameters to change. This is intended, but the problem is that there is no tolerance for small floating point errors.
Steps to reproduce
Run the following script twice, but the second time without adding 1e-12
to phi
(I used this CE to run this script: test.ce)
from ase.build import make_supercell
from icet import ClusterExpansion
from mchammer.calculators import ClusterExpansionCalculator
from mchammer.ensembles import VCSGCEnsemble
import numpy as np
ce = ClusterExpansion.read('test.ce')
chemical_symbols = ce.cluster_space.chemical_symbols
prim_structure = ce.cluster_space.primitive_structure
prim_structure.set_chemical_symbols(['Ag'])
atoms = make_supercell(prim_structure,
np.array([[-1, 1, 1],
[1, -1, 1],
[1, 1, -1]]))
calculator = ClusterExpansionCalculator(atoms, ce)
temperature = 300
phi = -1.1 + 1e-12
mc = VCSGCEnsemble(
calculator=calculator,
atoms=atoms,
ensemble_data_write_interval=100,
trajectory_write_interval=100,
temperature=temperature,
phis={'Ag': phi,
'Pd': -2 - phi},
kappa=200.0,
data_container='data.dc'
)
mc.run(number_of_trial_steps=100)
The second time it crashes saying
Traceback (most recent call last):
File "run_1.py", line 29, in <module>
data_container='data.dc'
File "/home/magnus/repos/icet/mchammer/ensembles/vcsgc_ensemble.py", line 154, in __init__
trajectory_write_interval=trajectory_write_interval)
File "/home/magnus/repos/icet/mchammer/ensembles/base_ensemble.py", line 118, in __init__
set(self.ensemble_parameters.items())))
ValueError: Ensemble parameters do not match with those stored in DataContainer file: {('phi_Pd', -0.900000000001), ('phi_Ag', -1.099999999999)}
This is of course not just a pathological example but a real problem I came across when intending to restart a run.