From 37a7acf0f5ed20183d694b6a68de31cd3ebd1d85 Mon Sep 17 00:00:00 2001 From: "Joshua A. Anderson" Date: Fri, 8 Mar 2024 12:46:15 -0500 Subject: [PATCH 1/7] Deprecate box1, box2, variant args. --- hoomd/BoxResizeUpdater.cc | 79 ++----------- hoomd/BoxResizeUpdater.h | 48 +++----- hoomd/BoxResizeUpdaterGPU.cc | 18 +-- hoomd/BoxResizeUpdaterGPU.h | 4 +- hoomd/update/box_resize.py | 221 ++++++++++++++++++++++------------- 5 files changed, 169 insertions(+), 201 deletions(-) diff --git a/hoomd/BoxResizeUpdater.cc b/hoomd/BoxResizeUpdater.cc index d484155ac1..6ab267ac74 100644 --- a/hoomd/BoxResizeUpdater.cc +++ b/hoomd/BoxResizeUpdater.cc @@ -15,21 +15,16 @@ using namespace std; namespace hoomd { -/*! \param sysdef System definition containing the particle data to set the box size on - \param Lx length of the x dimension over time - \param Ly length of the y dimension over time - \param Lz length of the z dimension over time - - The default setting is to scale particle positions along with the box. +/** @param sysdef System definition containing the particle data to set the box size on + @param trigger Steps on which to execute. + @param box Box as a function of time. + @param group Particles to scale. */ - BoxResizeUpdater::BoxResizeUpdater(std::shared_ptr sysdef, std::shared_ptr trigger, - std::shared_ptr box1, - std::shared_ptr box2, - std::shared_ptr variant, + std::shared_ptr box, std::shared_ptr group) - : Updater(sysdef, trigger), m_box1(box1), m_box2(box2), m_variant(variant), m_group(group) + : Updater(sysdef, trigger), m_box(box), m_group(group) { assert(m_pdata); assert(m_variant); @@ -41,60 +36,13 @@ BoxResizeUpdater::~BoxResizeUpdater() m_exec_conf->msg->notice(5) << "Destroying BoxResizeUpdater" << endl; } -/// Get box1 -std::shared_ptr BoxResizeUpdater::getBox1() - { - return m_box1; - } - -/// Set a new box1 -void BoxResizeUpdater::setBox1(std::shared_ptr box1) - { - m_box1 = box1; - } - -/// Get box2 -std::shared_ptr BoxResizeUpdater::getBox2() - { - return m_box2; - } - -void BoxResizeUpdater::setBox2(std::shared_ptr box2) - { - m_box2 = box2; - } - -/// Get the current box based on the timestep BoxDim BoxResizeUpdater::getCurrentBox(uint64_t timestep) { - Scalar min = m_variant->min(); - Scalar max = m_variant->max(); - Scalar cur_value = (*m_variant)(timestep); - Scalar scale = 0; - if (cur_value == max) - { - scale = 1; - } - else if (cur_value > min) - { - scale = (cur_value - min) / (max - min); - } - - const auto& box1 = *m_box1; - const auto& box2 = *m_box2; - Scalar3 new_L = box2.getL() * scale + box1.getL() * (1.0 - scale); - Scalar xy = box2.getTiltFactorXY() * scale + (1.0 - scale) * box1.getTiltFactorXY(); - Scalar xz = box2.getTiltFactorXZ() * scale + (1.0 - scale) * box1.getTiltFactorXZ(); - Scalar yz = box2.getTiltFactorYZ() * scale + (1.0 - scale) * box1.getTiltFactorYZ(); - - BoxDim new_box = BoxDim(new_L); - new_box.setTiltFactors(xy, xz, yz); - return new_box; + return BoxDim((*m_box)(timestep)); } -/** Perform the needed calculations to scale the box size - \param timestep Current time step of the simulation -*/ +/** @param timestep Current time step of the simulation + */ void BoxResizeUpdater::update(uint64_t timestep) { Updater::update(timestep); @@ -124,7 +72,6 @@ void BoxResizeUpdater::update(uint64_t timestep) } } -/// Scale particles to the new box and wrap any others back into the box void BoxResizeUpdater::scaleAndWrapParticles(const BoxDim& cur_box, const BoxDim& new_box) { ArrayHandle h_pos(m_pdata->getPositions(), @@ -171,13 +118,9 @@ void export_BoxResizeUpdater(pybind11::module& m) "BoxResizeUpdater") .def(pybind11::init, std::shared_ptr, - std::shared_ptr, - std::shared_ptr, - std::shared_ptr, + std::shared_ptr, std::shared_ptr>()) - .def_property("box1", &BoxResizeUpdater::getBox1, &BoxResizeUpdater::setBox1) - .def_property("box2", &BoxResizeUpdater::getBox2, &BoxResizeUpdater::setBox2) - .def_property("variant", &BoxResizeUpdater::getVariant, &BoxResizeUpdater::setVariant) + .def_property("box", &BoxResizeUpdater::getBox, &BoxResizeUpdater::setBox) .def_property_readonly("filter", [](const std::shared_ptr method) { return method->getGroup()->getFilter(); }) diff --git a/hoomd/BoxResizeUpdater.h b/hoomd/BoxResizeUpdater.h index a61c1b99ca..d0397c5446 100644 --- a/hoomd/BoxResizeUpdater.h +++ b/hoomd/BoxResizeUpdater.h @@ -13,14 +13,14 @@ #include "ParticleGroup.h" #include "Updater.h" #include "Variant.h" +#include "VectorVariant.h" #include #include #include #include -#ifndef __BOXRESIZEUPDATER_H__ -#define __BOXRESIZEUPDATER_H__ +#pragma once namespace hoomd { @@ -37,42 +37,28 @@ class PYBIND11_EXPORT BoxResizeUpdater : public Updater /// Constructor BoxResizeUpdater(std::shared_ptr sysdef, std::shared_ptr trigger, - std::shared_ptr box1, - std::shared_ptr box2, - std::shared_ptr variant, + std::shared_ptr box, std::shared_ptr m_group); /// Destructor virtual ~BoxResizeUpdater(); - /// Get the current m_box2 - std::shared_ptr getBox1(); - - /// Set a new m_box_1 - void setBox1(std::shared_ptr box1); - - /// Get the current m_box2 - std::shared_ptr getBox2(); - - /// Set a new m_box_2 - void setBox2(std::shared_ptr box2); - - /// Gets particle scaling filter - std::shared_ptr getGroup() + /// Set the box variant + void setBox(std::shared_ptr box) { - return m_group; + m_box = box; } - /// Set the variant for interpolation - void setVariant(std::shared_ptr variant) + /// Get the box variant + std::shared_ptr getBox() { - m_variant = variant; + return m_box; } - /// Get the variant for interpolation - std::shared_ptr getVariant() + /// Gets particle scaling filter + std::shared_ptr getGroup() { - return m_variant; + return m_group; } /// Get the current box for the given timestep @@ -85,10 +71,11 @@ class PYBIND11_EXPORT BoxResizeUpdater : public Updater virtual void scaleAndWrapParticles(const BoxDim& cur_box, const BoxDim& new_box); protected: - std::shared_ptr m_box1; ///< C++ box assoc with min - std::shared_ptr m_box2; ///< C++ box assoc with max - std::shared_ptr m_variant; //!< Variant that interpolates between boxes - std::shared_ptr m_group; //!< Selected particles to scale when resizing the box. + /// Box as a function of time. + std::shared_ptr m_box; + + /// Selected particles to scale when resizing the box. + std::shared_ptr m_group; }; namespace detail @@ -97,4 +84,3 @@ namespace detail void export_BoxResizeUpdater(pybind11::module& m); } // end namespace detail } // end namespace hoomd -#endif diff --git a/hoomd/BoxResizeUpdaterGPU.cc b/hoomd/BoxResizeUpdaterGPU.cc index 655fe52cad..6d3e1e891d 100644 --- a/hoomd/BoxResizeUpdaterGPU.cc +++ b/hoomd/BoxResizeUpdaterGPU.cc @@ -10,21 +10,11 @@ namespace hoomd { -/*! \param sysdef System definition containing the particle data to set the box size on - \param Lx length of the x dimension over time - \param Ly length of the y dimension over time - \param Lz length of the z dimension over time - - The default setting is to scale particle positions along with the box. -*/ - BoxResizeUpdaterGPU::BoxResizeUpdaterGPU(std::shared_ptr sysdef, std::shared_ptr trigger, - std::shared_ptr box1, - std::shared_ptr box2, - std::shared_ptr variant, + std::shared_ptr box, std::shared_ptr group) - : BoxResizeUpdater(sysdef, trigger, box1, box2, variant, group) + : BoxResizeUpdater(sysdef, trigger, box, group) { // only one GPU is supported if (!m_exec_conf->isCUDAEnabled()) @@ -87,9 +77,7 @@ void export_BoxResizeUpdaterGPU(pybind11::module& m) "BoxResizeUpdaterGPU") .def(pybind11::init, std::shared_ptr, - std::shared_ptr, - std::shared_ptr, - std::shared_ptr, + std::shared_ptr, std::shared_ptr>()); } diff --git a/hoomd/BoxResizeUpdaterGPU.h b/hoomd/BoxResizeUpdaterGPU.h index 18d7cf099b..bbc94a2182 100644 --- a/hoomd/BoxResizeUpdaterGPU.h +++ b/hoomd/BoxResizeUpdaterGPU.h @@ -29,9 +29,7 @@ class PYBIND11_EXPORT BoxResizeUpdaterGPU : public BoxResizeUpdater /// Constructor BoxResizeUpdaterGPU(std::shared_ptr sysdef, std::shared_ptr trigger, - std::shared_ptr box1, - std::shared_ptr box2, - std::shared_ptr variant, + std::shared_ptr box, std::shared_ptr m_group); /// Destructor diff --git a/hoomd/update/box_resize.py b/hoomd/update/box_resize.py index 9ae8fcf1e7..a1f2023720 100644 --- a/hoomd/update/box_resize.py +++ b/hoomd/update/box_resize.py @@ -6,24 +6,27 @@ .. invisible-code-block: python simulation = hoomd.util.make_example_simulation() - initial_box = simulation.state.box - box = initial_box - final_box = hoomd.Box.from_box(initial_box) - final_box.volume = final_box.volume * 2 + + inverse_volume_ramp = hoomd.variant.box.InverseVolumeRamp( + initial_box=hoomd.Box.cube(6), + final_volume=100, + t_start=1_000, + t_ramp=21_000) """ +import warnings + import hoomd from hoomd.operation import Updater from hoomd.box import Box from hoomd.data.parameterdicts import ParameterDict -from hoomd.variant import Variant, Constant from hoomd import _hoomd from hoomd.filter import ParticleFilter, All from hoomd.trigger import Periodic class BoxResize(Updater): - """Resizes the box between an initial and final box. + """Vary the simulation box size as a function of time. Args: trigger (hoomd.trigger.trigger_like): The trigger to activate this @@ -36,30 +39,11 @@ class BoxResize(Updater): between the two boxes. filter (hoomd.filter.filter_like): The subset of particle positions to update (defaults to `hoomd.filter.All`). + box (hoomd.variant.box.BoxVariant): Box as a function of time. - `BoxResize` resizes the box between gradually from the initial box to the - final box. The simulation box follows the linear interpolation between the - initial and final boxes where the minimum of the variant gives `box1` and - the maximum gives `box2`: - - .. math:: - - \\begin{align*} - L_{x}' &= \\lambda L_{2x} + (1 - \\lambda) L_{1x} \\\\ - L_{y}' &= \\lambda L_{2y} + (1 - \\lambda) L_{1y} \\\\ - L_{z}' &= \\lambda L_{2z} + (1 - \\lambda) L_{1z} \\\\ - xy' &= \\lambda xy_{2} + (1 - \\lambda) xy_{1} \\\\ - xz' &= \\lambda xz_{2} + (1 - \\lambda) xz_{1} \\\\ - yz' &= \\lambda yz_{2} + (1 - \\lambda) yz_{1} \\\\ - \\end{align*} - - Where `box1` is :math:`(L_{1x}, L_{1y}, L_{1z}, xy_1, xz_1, yz_1)`, - `box2` is :math:`(L_{2x}, L_{2y}, L_{2z}, xy_2, xz_2, yz_2)`, - :math:`\\lambda = \\frac{f(t) - \\min f}{\\max f - \\min f}`, :math:`t` - is the timestep, and :math:`f(t)` is given by `variant`. - - For each particle :math:`i` matched by `filter`, `BoxResize` scales the - particle to fit in the new box: + `BoxResize` resizes the simulation box as a function of time. For each + particle :math:`i` matched by `filter`, `BoxResize` scales the particle to + fit in the new box: .. math:: @@ -68,7 +52,7 @@ class BoxResize(Updater): \\frac{\\vec{a}_1' + \\vec{a}_2' + \\vec{a}_3'}{2} where :math:`\\vec{a}_k'` are the new box vectors determined by - :math:`(L_x', L_y', L_z', xy', xz', yz')` and the scale factors are + :math:`box` evaluated at the current time step and the scale factors are determined by the current particle position :math:`\\vec{r}_i` and the old box vectors :math:`\\vec{a}_k`: @@ -85,13 +69,17 @@ class BoxResize(Updater): \\vec{r_j} \\leftarrow \\mathrm{minimum\\_image}_{\\vec{a}_k}' (\\vec{r}_j) - Important: - The passed `Variant` must be bounded on the interval :math:`t \\in - [0,\\infty)` or the behavior of the updater is undefined. + Note: + For backward compatibility, you may set ``box1``, ``box2``, and + ``variant`` which is equivalent to:: + + box = hoomd.variant.box.Interpolate(initial_box=box1, + final_box=box2, + variant=variant) Warning: - Rescaling particles fails in HPMC simulations with more than one MPI - rank. + Rescaling particles in HPMC simulations with hard particles may + introduce overlaps. Note: When using rigid bodies, ensure that the `BoxResize` updater is last in @@ -100,48 +88,24 @@ class BoxResize(Updater): deformed. `hoomd.md.Integrator` will run after the last updater and resets the constituent particle positions before computing forces. + .. deprecated:: 4.6.0 + The arguments ``box1``, ``box2``, and ``variant`` are deprecated. Use + ``box``. + .. rubric:: Example: .. code-block:: python box_resize = hoomd.update.BoxResize(trigger=hoomd.trigger.Periodic(10), - box1=initial_box, - box2=final_box, - variant=hoomd.variant.Ramp( - A=0, - B=1, - t_start=simulation.timestep, - t_ramp=20000)) + box1=inverse_volume_ramp) simulation.operations.updaters.append(box_resize) Attributes: - box1 (hoomd.Box): The box associated with the minimum of the - passed variant. + box (hoomd.variant.box.BoxVariant): The box as a function of time. .. rubric:: Example: - .. code-block:: python - - box_resize.box1 = initial_box - - box2 (hoomd.Box): The box associated with the maximum of the - passed variant. - - .. rubric:: Example: - - .. code-block:: python - - box_resize.box2 = final_box - - variant (hoomd.variant.Variant): A variant used to interpolate between - the two boxes. - - .. rubric:: Example: - - .. code-block:: python - - box_resize.variant = hoomd.variant.Ramp( - A=0, B=1, t_start=simulation.timestep, t_ramp=20000) + box_resize.box = inverse_volume_ramp filter (hoomd.filter.filter_like): The subset of particles to update. @@ -153,16 +117,40 @@ class BoxResize(Updater): filter_ = box_resize.filter """ - def __init__(self, trigger, box1, box2, variant, filter=All()): - params = ParameterDict(box1=Box, - box2=Box, - variant=Variant, + def __init__( + self, + trigger, + box1=None, + box2=None, + variant=None, + filter=All(), + box=None, + ): + params = ParameterDict(box=hoomd.variant.box.BoxVariant, filter=ParticleFilter) - params['box1'] = box1 - params['box2'] = box2 - params['variant'] = variant - params['trigger'] = trigger - params['filter'] = filter + + if box is not None and (box1 is not None or box2 is not None + or variant is not None): + raise ValueError( + 'box1, box2, and variant must be None when box is set') + + if box is None and not (box1 is not None and box2 is not None + and variant is not None): + raise ValueError( + 'box1, box2, and variant must not be None when box is None') + + if box is not None: + self._using_deprecated_box = False + else: + warnings.warn('box1, box2, and variant are deprecated, use `box`', + FutureWarning) + + box = hoomd.variant.box.Interpolate(initial_box=box1, + final_box=box2, + variant=variant) + self._using_deprecated_box = True + + params.update({'box': box, 'filter': filter}) self._param_dict.update(params) super().__init__(trigger) @@ -170,12 +158,78 @@ def _attach_hook(self): group = self._simulation.state._get_group(self.filter) if isinstance(self._simulation.device, hoomd.device.CPU): self._cpp_obj = _hoomd.BoxResizeUpdater( - self._simulation.state._cpp_sys_def, self.trigger, - self.box1._cpp_obj, self.box2._cpp_obj, self.variant, group) + self._simulation.state._cpp_sys_def, self.trigger, self.box, + group) else: self._cpp_obj = _hoomd.BoxResizeUpdaterGPU( - self._simulation.state._cpp_sys_def, self.trigger, - self.box1._cpp_obj, self.box2._cpp_obj, self.variant, group) + self._simulation.state._cpp_sys_def, self.trigger, self.box, + group) + + @property + def box1(self): + """hoomd.Box: The box associated with the minimum of the passed variant. + + .. deprecated:: 4.6.0 + + Use `box`. + """ + warnings.warn('box1 is deprecated, use `box`.', FutureWarning) + if self._using_deprecated_box: + return self.box.initial_box + + raise RuntimeError('box1 is not available when box is not None.') + + @box1.setter + def box1(self, box): + warnings.warn('box1 is deprecated, use `box`.', FutureWarning) + if self._using_deprecated_box: + self.box.initial_box = box + + raise RuntimeError('box1 is not available when box is not None.') + + @property + def box2(self): + """hoomd.Box: The box associated with the maximum of the passed variant. + + .. deprecated:: 4.6.0 + + Use `box`. + """ + warnings.warn('box2 is deprecated, use `box`.', FutureWarning) + if self._using_deprecated_box: + return self.box.final_box + + raise RuntimeError('box2 is not available when box is not None.') + + @box2.setter + def box2(self, box): + warnings.warn('box2 is deprecated, use `box`.', FutureWarning) + if self._using_deprecated_box: + self.box.final_box = box + + raise RuntimeError('box2 is not available when box is not None.') + + @property + def variant(self): + """hoomd.variant.Variant: A variant used to interpolate boxes. + + .. deprecated:: 4.6.0 + + Use `box`. + """ + warnings.warn('variant is deprecated, use `box`.', FutureWarning) + if self._using_deprecated_box: + return self.box.variant + + raise RuntimeError('variant is not available when box is not None.') + + @variant.setter + def variant(self, variant): + warnings.warn('variant is deprecated, use `box`.', FutureWarning) + if self._using_deprecated_box: + self.box.final_box = variant + + raise RuntimeError('variant is not available when box is not None.') def get_box(self, timestep): """Get the box for a given timestep. @@ -221,14 +275,13 @@ def update(state, box, filter=All()): """ group = state._get_group(filter) + box_variant = hoomd.variant.box.Constant(box) + if isinstance(state._simulation.device, hoomd.device.CPU): updater = _hoomd.BoxResizeUpdater(state._cpp_sys_def, Periodic(1), - state.box._cpp_obj, box._cpp_obj, - Constant(1), group) + box_variant, group) else: updater = _hoomd.BoxResizeUpdaterGPU(state._cpp_sys_def, - Periodic(1), - state.box._cpp_obj, - box._cpp_obj, Constant(1), + Periodic(1), box_variant, group) updater.update(state._simulation.timestep) From 5f7f7d4366a59382a9dbedc41d139a82eb1c4bd1 Mon Sep 17 00:00:00 2001 From: "Joshua A. Anderson" Date: Fri, 8 Mar 2024 13:42:38 -0500 Subject: [PATCH 2/7] Add unit tests for new API. --- hoomd/pytest/test_box_resize.py | 64 ++++++++++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 5 deletions(-) diff --git a/hoomd/pytest/test_box_resize.py b/hoomd/pytest/test_box_resize.py index 299f7bbbd6..a247e2ea7c 100644 --- a/hoomd/pytest/test_box_resize.py +++ b/hoomd/pytest/test_box_resize.py @@ -9,11 +9,6 @@ from hoomd.error import MutabilityError -@pytest.fixture(scope="function") -def rng(): - return np.random.default_rng(42) - - _n_points = 10 @@ -256,3 +251,62 @@ def test_mutability_error(simulation_factory, two_particle_snapshot_factory): with pytest.raises(MutabilityError): box_op.filter = filt + + +def test_new_api(simulation_factory, two_particle_snapshot_factory): + sim = simulation_factory(two_particle_snapshot_factory()) + inverse_volume_ramp = hoomd.variant.box.InverseVolumeRamp( + initial_box=hoomd.Box.cube(6), + final_volume=100, + t_start=1_000, + t_ramp=21_000) + + box_resize = hoomd.update.BoxResize(trigger=hoomd.trigger.Periodic(1), + filter=hoomd.filter.All(), + box=inverse_volume_ramp) + sim.operations.updaters.append(box_resize) + + sim.run(0) + + assert box_resize.box is inverse_volume_ramp + +def test_invalid_api(variant, trigger): + box_variant = hoomd.variant.box.InverseVolumeRamp( + initial_box=hoomd.Box.cube(6), + final_volume=100, + t_start=1_000, + t_ramp=21_000) + + box1 = hoomd.Box.cube(10) + box2 = hoomd.Box.cube(20) + + with pytest.raises(ValueError): + hoomd.update.BoxResize(trigger=trigger) + with pytest.raises(ValueError): + hoomd.update.BoxResize(trigger=trigger, box1=box1) + with pytest.raises(ValueError): + hoomd.update.BoxResize(trigger=trigger, box1=box1, box2=box2) + with pytest.raises(ValueError): + hoomd.update.BoxResize(trigger=trigger, box2=box2, variant=variant) + with pytest.raises(ValueError): + hoomd.update.BoxResize(trigger=trigger, box1=box1, box2=box2, variant=variant, box=box_variant) + with pytest.raises(ValueError): + hoomd.update.BoxResize(trigger=trigger, box1=box1, box=box_variant) + with pytest.raises(ValueError): + hoomd.update.BoxResize(trigger=trigger, box2=box2, box=box_variant) + with pytest.raises(ValueError): + hoomd.update.BoxResize(trigger=trigger, variant=variant, box=box_variant) + + box_resize = hoomd.update.BoxResize(trigger=trigger, box=box_variant) + with pytest.raises(RuntimeError): + box_resize.box1 + with pytest.raises(RuntimeError): + box_resize.box2 + with pytest.raises(RuntimeError): + box_resize.variant + with pytest.raises(RuntimeError): + box_resize.box1 = box1 + with pytest.raises(RuntimeError): + box_resize.box2 = box2 + with pytest.raises(RuntimeError): + box_resize.variant = variant From 40fe4e39a7da9c14f56ff336eb8d419c32bffc92 Mon Sep 17 00:00:00 2001 From: "Joshua A. Anderson" Date: Fri, 8 Mar 2024 14:26:17 -0500 Subject: [PATCH 3/7] Revise documentation. --- hoomd/update/box_resize.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/hoomd/update/box_resize.py b/hoomd/update/box_resize.py index a1f2023720..548d385ed5 100644 --- a/hoomd/update/box_resize.py +++ b/hoomd/update/box_resize.py @@ -51,10 +51,10 @@ class BoxResize(Updater): s_z \\vec{a}_3' - \\frac{\\vec{a}_1' + \\vec{a}_2' + \\vec{a}_3'}{2} - where :math:`\\vec{a}_k'` are the new box vectors determined by - :math:`box` evaluated at the current time step and the scale factors are - determined by the current particle position :math:`\\vec{r}_i` and the old - box vectors :math:`\\vec{a}_k`: + where :math:`\\vec{a}_k'` are the new box vectors determined by `box` + evaluated at the current time step and the scale factors are determined + by the current particle position :math:`\\vec{r}_i` and the previous box + vectors :math:`\\vec{a}_k`: .. math:: @@ -97,7 +97,7 @@ class BoxResize(Updater): .. code-block:: python box_resize = hoomd.update.BoxResize(trigger=hoomd.trigger.Periodic(10), - box1=inverse_volume_ramp) + box=inverse_volume_ramp) simulation.operations.updaters.append(box_resize) Attributes: @@ -105,6 +105,8 @@ class BoxResize(Updater): .. rubric:: Example: + .. code-block:: python + box_resize.box = inverse_volume_ramp filter (hoomd.filter.filter_like): The subset of particles to From 6f98c24903dbcec195e825ade3d4e634b99850de Mon Sep 17 00:00:00 2001 From: "Joshua A. Anderson" Date: Tue, 12 Mar 2024 14:47:45 -0400 Subject: [PATCH 4/7] List deprecation in documentation. --- sphinx-doc/deprecated.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sphinx-doc/deprecated.rst b/sphinx-doc/deprecated.rst index 4e18ebcc51..93fb30c596 100644 --- a/sphinx-doc/deprecated.rst +++ b/sphinx-doc/deprecated.rst @@ -47,3 +47,7 @@ documentation for more information on warning filters. * ``GPU.devices`` (since 4.5.0) * Use ``device``. + +* ``box1``, ``box2``, and ``variant`` arguments to ``hoomd.update.BoxResize``. + + * Use ``box``. From c4e522ddafe271bf1e035d17d88d51b154d55ae5 Mon Sep 17 00:00:00 2001 From: "Joshua A. Anderson" Date: Tue, 12 Mar 2024 14:48:58 -0400 Subject: [PATCH 5/7] Run pre-commit. --- hoomd/pytest/test_box_resize.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/hoomd/pytest/test_box_resize.py b/hoomd/pytest/test_box_resize.py index a247e2ea7c..eb56858c29 100644 --- a/hoomd/pytest/test_box_resize.py +++ b/hoomd/pytest/test_box_resize.py @@ -8,7 +8,6 @@ from hoomd.conftest import operation_pickling_check from hoomd.error import MutabilityError - _n_points = 10 @@ -270,12 +269,13 @@ def test_new_api(simulation_factory, two_particle_snapshot_factory): assert box_resize.box is inverse_volume_ramp + def test_invalid_api(variant, trigger): box_variant = hoomd.variant.box.InverseVolumeRamp( initial_box=hoomd.Box.cube(6), final_volume=100, t_start=1_000, - t_ramp=21_000) + t_ramp=21_000) box1 = hoomd.Box.cube(10) box2 = hoomd.Box.cube(20) @@ -289,13 +289,19 @@ def test_invalid_api(variant, trigger): with pytest.raises(ValueError): hoomd.update.BoxResize(trigger=trigger, box2=box2, variant=variant) with pytest.raises(ValueError): - hoomd.update.BoxResize(trigger=trigger, box1=box1, box2=box2, variant=variant, box=box_variant) + hoomd.update.BoxResize(trigger=trigger, + box1=box1, + box2=box2, + variant=variant, + box=box_variant) with pytest.raises(ValueError): hoomd.update.BoxResize(trigger=trigger, box1=box1, box=box_variant) with pytest.raises(ValueError): hoomd.update.BoxResize(trigger=trigger, box2=box2, box=box_variant) with pytest.raises(ValueError): - hoomd.update.BoxResize(trigger=trigger, variant=variant, box=box_variant) + hoomd.update.BoxResize(trigger=trigger, + variant=variant, + box=box_variant) box_resize = hoomd.update.BoxResize(trigger=trigger, box=box_variant) with pytest.raises(RuntimeError): From f66b49f61c6108d09203fc1ec9406da3a7a6db8f Mon Sep 17 00:00:00 2001 From: "Joshua A. Anderson" Date: Tue, 12 Mar 2024 14:53:57 -0400 Subject: [PATCH 6/7] Remove unused assert. --- hoomd/BoxResizeUpdater.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/hoomd/BoxResizeUpdater.cc b/hoomd/BoxResizeUpdater.cc index 6ab267ac74..7e11f59c1b 100644 --- a/hoomd/BoxResizeUpdater.cc +++ b/hoomd/BoxResizeUpdater.cc @@ -27,7 +27,6 @@ BoxResizeUpdater::BoxResizeUpdater(std::shared_ptr sysdef, : Updater(sysdef, trigger), m_box(box), m_group(group) { assert(m_pdata); - assert(m_variant); m_exec_conf->msg->notice(5) << "Constructing BoxResizeUpdater" << endl; } From 6c17eaba6449acfd56a33366072e52b291213665 Mon Sep 17 00:00:00 2001 From: Tim Moore Date: Tue, 12 Mar 2024 17:50:55 -0400 Subject: [PATCH 7/7] Add __reduce__() to box variants to allow pickling --- hoomd/variant/box.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/hoomd/variant/box.py b/hoomd/variant/box.py index 9c04cd9016..31c2db4ab4 100644 --- a/hoomd/variant/box.py +++ b/hoomd/variant/box.py @@ -128,6 +128,10 @@ def __init__(self, initial_box, final_box, variant): _hoomd.VectorVariantBoxInterpolate.__init__(self, box1._cpp_obj, box2._cpp_obj, variant) + def __reduce__(self): + """Reduce values to picklable format.""" + return (type(self), (self.initial_box, self.final_box, self.variant)) + @property def initial_box(self): """hoomd.Box: The initial box.""" @@ -191,6 +195,11 @@ def __init__(self, initial_box, final_volume, t_start, t_ramp): _hoomd.VectorVariantBoxInverseVolumeRamp.__init__( self, box._cpp_obj, final_volume, t_start, t_ramp) + def __reduce__(self): + """Reduce values to picklable format.""" + return (type(self), (self.initial_box, self.final_volume, self.t_start, + self.t_ramp)) + @property def initial_box(self): """hoomd.Box: The initial box."""