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

Small changes and updates #304

Merged
merged 5 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions docs/src/citing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ If you use the charge neutral semigrand canonical sampling or any related functi
please cite the following work,

Xie, F., Zhong, P., Barroso-Luque, L., Ouyang, B. & Ceder, G.
`Grand-canonical Monte-Carlo simulation methods for charge-decorated cluster
expansions <https://arxiv.org/abs/2210.01165>`_ [arxiv:2210.01165].

`Semigrand-canonical Monte-Carlo simulation methods for charge-decorated cluster
expansions <https://doi.org/10.1016/j.commatsci.2022.112000>`_
Computational Materials Science 218, 112000 (2023).

Coulomb electrostatic interactions
==================================
Expand Down
16 changes: 9 additions & 7 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,19 @@ install_requires =
[options.extras_require]
docs =
sphinx >= 5.3
pydata-sphinx-theme ==0.12.0
ipython ==8.2.0
nbsphinx ==0.8.10
nbsphinx-link ==1.3.0
nb2plots ==0.6.1
pydata-sphinx-theme >=0.12.0
ipython >=8.2.0
nbsphinx >=0.8.10
nbsphinx-link >=1.3.0
nb2plots >=0.6.1
tests =
pytest ==7.2.0
pytest-cov ==4.0.0
pytest >=7.2.0
pytest-cov >=4.0.0
scikit-learn >=1.1.2
h5py >=3.6.0
coverage
polytope
cvxpy
dev =
pre-commit >=2.12.1
cython >=0.29.32
Expand Down
24 changes: 17 additions & 7 deletions smol/moca/sampler/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ def __init__(
self.natural_params = ensemble.natural_parameters
self._seed = seed if seed is not None else np.random.SeedSequence().entropy
self._rng = np.random.default_rng(self._seed)
self._compute_features = ensemble.compute_feature_vector
self._feature_change = ensemble.compute_feature_vector_change
self._ensemble = ensemble
self.trace = StepTrace(accepted=np.array([True]))
self._usher, self._bias = None, None

Expand All @@ -93,6 +92,11 @@ def __init__(
# run a initial step to populate trace values
_ = self.single_step(np.zeros(ensemble.num_sites, dtype=int))

@property
def ensemble(self):
"""Return the ensemble instance."""
return self._ensemble

@property
def mcusher(self):
"""Get the MCUsher."""
Expand Down Expand Up @@ -157,7 +161,7 @@ def compute_initial_trace(self, occupancy):
"""
trace = Trace()
trace.occupancy = occupancy
trace.features = self._compute_features(occupancy)
trace.features = self.ensemble.compute_feature_vector(occupancy)
# set scalar values into shape (1,) array for sampling consistency.
trace.enthalpy = np.array([np.dot(self.natural_params, trace.features)])
if self.bias is not None:
Expand Down Expand Up @@ -253,7 +257,9 @@ def single_step(self, occupancy):
"""
step = self._usher.propose_step(occupancy)
log_factor = self._usher.compute_log_priori_factor(occupancy, step)
self.trace.delta_trace.features = self._feature_change(occupancy, step)
self.trace.delta_trace.features = self.ensemble.compute_feature_vector_change(
occupancy, step
)
self.trace.delta_trace.enthalpy = np.array(
np.dot(self.natural_params, self.trace.delta_trace.features)
)
Expand Down Expand Up @@ -303,7 +309,9 @@ def single_step(self, occupancy):
"""
step = self._usher.propose_step(occupancy)
log_factor = self._usher.compute_log_priori_factor(occupancy, step)
self.trace.delta_trace.features = self._feature_change(occupancy, step)
self.trace.delta_trace.features = self.ensemble.compute_feature_vector_change(
occupancy, step
)
self.trace.delta_trace.enthalpy = np.array(
np.dot(self.natural_params, self.trace.delta_trace.features)
)
Expand Down Expand Up @@ -514,7 +522,9 @@ def single_step(self, occupancy):
"""
bin_id = self._get_bin_id(self._current_enthalpy)
step = self._usher.propose_step(occupancy)
self.trace.delta_trace.features = self._feature_change(occupancy, step)
self.trace.delta_trace.features = self.ensemble.compute_feature_vector_change(
occupancy, step
)
self.trace.delta_trace.enthalpy = np.array(
np.dot(self.natural_params, self.trace.delta_trace.features)
)
Expand Down Expand Up @@ -612,7 +622,7 @@ def set_aux_state(self, occupancy, *args, **kwargs):
This is necessary for WangLandau to work properly because
it needs to store the current enthalpy and features.
"""
features = np.array(self._compute_features(occupancy))
features = np.array(self.ensemble.compute_feature_vector(occupancy))
enthalpy = np.dot(features, self.natural_params)
self._current_features = features
self._current_enthalpy = enthalpy
Expand Down