Skip to content

Commit

Permalink
Getting there
Browse files Browse the repository at this point in the history
  • Loading branch information
ceriottm committed Nov 20, 2023
1 parent b0cc41b commit 393c106
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 74 deletions.
4 changes: 2 additions & 2 deletions ipi/engine/motion/al6xxx_kmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import collections

from ipi.engine.motion import Motion, GeopMotion
from ipi.utils.depend import dstrip, depend_value, dd
from ipi.utils.depend import dstrip, depend_value
from ipi.engine.cell import Cell
from ipi.utils.units import Constants
import ipi.utils.io as io
Expand Down Expand Up @@ -164,7 +164,7 @@ def __init__(
self.idx = idx

# the KMC step is variable and so it cannot be stored as proper timing
dd(self).dt = depend_value(name="dt", value=0.0)
self._dt = depend_value(name="dt", value=0.0)
self.fixatoms = np.asarray([])
self.fixcom = True
self.optimizer = [None] * self.neval
Expand Down
10 changes: 6 additions & 4 deletions ipi/engine/motion/alchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import numpy as np

from ipi.engine.motion import Motion
from ipi.utils.depend import *
from ipi.utils.depend import inject_depend_properties
from ipi.utils.units import Constants


Expand Down Expand Up @@ -46,8 +46,7 @@ def __init__(
self.names = names
self.nxc = nxc

dself = dd(self)
dself.ealc = depend_value(name="ealc")
self._ealc = depend_value(name="ealc")

Check warning on line 49 in ipi/engine/motion/alchemy.py

View workflow job for this annotation

GitHub Actions / lint

F821 undefined name 'depend_value'
if ealc is not None:
self.ealc = ealc
else:
Expand All @@ -70,7 +69,7 @@ def bind(self, ens, beads, cell, bforce, nm, prng, omaker):
"""

super(AlchemyMC, self).bind(ens, beads, cell, bforce, nm, prng, omaker)
self.ensemble.add_econs(dd(self).ealc)
self.ensemble.add_econs(self._ealc)

def AXlist(self, atomtype):
"""This compile a list of atoms ready for exchanges."""
Expand Down Expand Up @@ -158,3 +157,6 @@ def step(self, step=None):

# adjusts the conserved quantity counter based on the change in spring energy
self.ealc += -difspring


inject_depend_properties(AlchemyMC, ["ealc"])
8 changes: 5 additions & 3 deletions ipi/engine/motion/atomswap.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ def __init__(
self.names = names
self.nxc = nxc

dself = dd(self)
dself.ealc = depend_value(name="ealc")
self._ealc = depend_value(name="ealc")
if ealc is not None:
self.ealc = ealc
else:
Expand All @@ -65,7 +64,7 @@ def bind(self, ens, beads, cell, bforce, nm, prng, omaker):
"""

super(AtomSwap, self).bind(ens, beads, cell, bforce, nm, prng, omaker)
self.ensemble.add_econs(dd(self).ealc)
self.ensemble.add_econs(self._ealc)
self.dbeads = self.beads.copy()
self.dcell = self.cell.copy()
self.dforces = self.forces.copy(self.dbeads, self.dcell)
Expand Down Expand Up @@ -133,3 +132,6 @@ def step(self, step=None):
self.forces.transfer_forces(self.dforces)

self.ealc += -(new_energy - old_energy)


inject_depend_properties(AtomSwap, ["ealc"])
8 changes: 5 additions & 3 deletions ipi/engine/motion/constrained_dynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,10 @@ def bind(self, ens, beads, nm, cell, bforce, prng, omaker):
self.csolver.bind(beads)


class ConstraintSolverBase(dobject):
inject_depend_properties(ConstrainedDynamics, ["dt", "nmts", "splitting"])


class ConstraintSolverBase:
"""Empty base class for the constraint solver. Provides the interface
that must be used to offer constraint functionalities to an integrator.
"""
Expand Down Expand Up @@ -229,7 +232,7 @@ def proj_manifold(self, beads, stepsize=None, proj_p=True):
raise NotImplementedError()


inject_depend_properties(ConstrainedDynamics, ["dt", "nmts", "splitting"])
inject_depend_properties(ConstraintSolverBase, ["dt"])


class ConstraintSolver(ConstraintSolverBase):
Expand Down Expand Up @@ -267,7 +270,6 @@ def proj_cotangent(self):
(sparsely).
"""

# m3 = dstrip(self.beads.m3[0])
p = dstrip(self.beads.p[0]).copy()
self.beads.p.hold()

Expand Down
42 changes: 29 additions & 13 deletions ipi/engine/thermostats.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def __init__(self, temp=1.0, dt=1.0, ethermo=0.0):
Defaults to 0.0. Will be non-zero if the thermostat is
initialised from a checkpoint file.
"""

self._temp = depend_value(name="temp", value=temp)
self._dt = depend_value(name="dt", value=dt)
self._ethermo = depend_value(name="ethermo", value=ethermo)
Expand Down Expand Up @@ -111,8 +111,8 @@ def bind(self, beads=None, atoms=None, pm=None, nm=None, prng=None, fixdof=None)
self._p = beads.p.flatten()
self._m = beads.m3.flatten()
elif atoms is not None:
self._p = dd(atoms).p
self._m = dd(atoms).m3
self._p = atoms._p
self._m = atoms._m3
elif pm is not None:
self._p = pm[
0
Expand Down Expand Up @@ -186,7 +186,7 @@ def __init__(self, temp=1.0, dt=1.0, tau=1.0, ethermo=0.0):
"""

super(ThermoLangevin, self).__init__(temp, dt, ethermo)

self._dt = depend_value(value=dt, name="dt")
self._tau = depend_value(value=tau, name="tau")
self._T = depend_value(
Expand Down Expand Up @@ -215,7 +215,11 @@ def step(self):
self.p = p
self.ethermo = et

inject_depend_properties(Thermostat, ["temp", "dt", "ethermo", "p", "m", "sm", "dt", "tau", "T", "S"])

inject_depend_properties(
Thermostat, ["temp", "dt", "ethermo", "p", "m", "sm", "dt", "tau", "T", "S"]
)


class ThermoPILE_L(Thermostat):

Expand Down Expand Up @@ -419,10 +423,12 @@ def step(self):
for t in self._thermos:
t.step()
self.nm.pnm.resume()
dd(self).ethermo.resume()
self._ethermo.resume()


inject_depend_properties(ThermoPILE_L, ["pilescale", "pilect", "npilect", "tauk"])


class ThermoSVR(Thermostat):

"""Represents a stochastic velocity rescaling thermostat.
Expand Down Expand Up @@ -457,7 +463,7 @@ def __init__(self, temp=1.0, dt=1.0, tau=1.0, ethermo=0.0):
"""

super(ThermoSVR, self).__init__(temp, dt, ethermo)

self._tau = depend_value(value=tau, name="tau")
self._et = depend_value(
name="et", func=self.get_et, dependencies=[self._tau, self._dt]
Expand Down Expand Up @@ -574,8 +580,10 @@ def bind(self, beads=None, atoms=None, pm=None, nm=None, prng=None, fixdof=None)
t.ethermo = prev_ethermo / nm.nbeads
self._ethermo._func = self.get_ethermo


inject_depend_properties(ThermoSVR, ["et", "K", "pilescale", "pilect", "npilect"])


class ThermoGLE(Thermostat):

"""Represents a generalized Langevin equation thermostat.
Expand Down Expand Up @@ -699,7 +707,7 @@ def bind(self, beads=None, atoms=None, pm=None, nm=None, prng=None, fixdof=None)

super(ThermoGLE, self).bind(
beads=beads, atoms=atoms, pm=pm, prng=prng, fixdof=fixdof
)
)

# allocates, initializes or restarts an array of s's
if self.s.shape != (self.ns + 1, len(self._m)):
Expand Down Expand Up @@ -733,8 +741,10 @@ def step(self):

self.p = self.s[0] * self.sm


inject_depend_properties(ThermoGLE, ["A", "C"])


class ThermoNMGLE(Thermostat):

"""Represents a 'normal-modes' generalized Langevin equation thermostat.
Expand Down Expand Up @@ -920,8 +930,10 @@ def get_ethermo(self):
et += t.ethermo
return et


inject_depend_properties(ThermoNMGLE, ["A", "C"])


class ThermoNMGLEG(ThermoNMGLE):

"""Represents a 'normal-modes' generalized Langevin equation thermostat + SVR.
Expand Down Expand Up @@ -970,7 +982,7 @@ def bind(self, beads=None, atoms=None, pm=None, nm=None, prng=None, fixdof=None)
dpipe(self._dt, t._dt)
dpipe(self._tau, t._tau)

dd(self).ethermo.add_dependency(t._ethermo)
self._ethermo.add_dependency(t._ethermo)
self._thermos.append(t)


Expand Down Expand Up @@ -1108,8 +1120,10 @@ def step(self):

self.idstep = not self.idstep


inject_depend_properties(ThermoCL, ["idtau", "intau", "apat", "lgT", "inT", "idT"])


class ThermoFFL(Thermostat):

"""Represents a fast-forward langevin thermostat.
Expand Down Expand Up @@ -1149,7 +1163,7 @@ def __init__(self, temp=1.0, dt=1.0, tau=1.0, ethermo=0.0, flip="rescale"):
"""

super(ThermoFFL, self).__init__(temp, dt, ethermo)

self._dt = depend_value(value=dt, name="dt")
self._tau = depend_value(value=tau, name="tau")
self._T = depend_value(
Expand Down Expand Up @@ -1218,8 +1232,10 @@ def step(self):
self.p = p
self.ethermo = et


inject_depend_properties(ThermoFFL, "flip")


class MultiThermo(Thermostat):
def __init__(self, temp=1.0, dt=1.0, ethermo=0.0, thermolist=None):
"""Initialises Thermostat.
Expand All @@ -1231,7 +1247,7 @@ def __init__(self, temp=1.0, dt=1.0, ethermo=0.0, thermolist=None):
Defaults to 0.0. Will be non-zero if the thermostat is
initialised from a checkpoint file.
"""

self.tlist = thermolist
self._temp = depend_value(name="temp", value=temp)
self._dt = depend_value(name="dt", value=dt)
Expand All @@ -1252,9 +1268,9 @@ def bind(self, beads=None, atoms=None, pm=None, nm=None, prng=None, fixdof=None)
# just binds all the sub-thermostats
for t in self.tlist:
t.bind(beads=beads, atoms=atoms, pm=pm, nm=nm, prng=prng, fixdof=fixdof)
dd(self).ethermo.add_dependency(t._ethermo)
self._ethermo.add_dependency(t._ethermo)

dd(self).ethermo._func = self.get_ethermo
self._ethermo._func = self.get_ethermo

def step(self):
"""Steps through all sub-thermostats."""
Expand Down
6 changes: 3 additions & 3 deletions ipi/inputs/thermostats.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,20 +207,20 @@ def store(self, thermo):
elif type(thermo) is ethermostats.ThermoGLE:
self.mode.store("gle")
self.A.store(thermo.A)
if dd(thermo).C._func is None:
if thermo._C._func is None:
self.C.store(thermo.C)
self.s.store(thermo.s)
elif type(thermo) is ethermostats.ThermoNMGLE:
self.mode.store("nm_gle")
self.A.store(thermo.A)
if dd(thermo).C._func is None:
if thermo._C._func is None:
self.C.store(thermo.C)
self.s.store(thermo.s)
elif type(thermo) is ethermostats.ThermoNMGLEG:
self.mode.store("nm_gle_g")
self.A.store(thermo.A)
self.tau.store(thermo.tau)
if dd(thermo).C._func is None:
if thermo._C._func is None:
self.C.store(thermo.C)
self.s.store(thermo.s)
elif type(thermo) is ethermostats.ThermoCL:
Expand Down
Loading

0 comments on commit 393c106

Please sign in to comment.