Skip to content

Commit

Permalink
ruff-format
Browse files Browse the repository at this point in the history
  • Loading branch information
joaander committed Nov 27, 2024
1 parent d51b03d commit 8c63de3
Show file tree
Hide file tree
Showing 258 changed files with 14,798 additions and 11,448 deletions.
2 changes: 1 addition & 1 deletion example_plugins/pair_plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

from hoomd.pair_plugin import pair

__all__ = ['pair']
__all__ = ["pair"]
8 changes: 5 additions & 3 deletions example_plugins/pair_plugin/pair.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ class ExamplePair(pair.Pair):
_cpp_class_name = "PotentialPairExample"
_accepted_modes = ("none", "shift", "xplor")

def __init__(self, nlist, default_r_cut=None, default_r_on=0., mode='none'):
def __init__(self, nlist, default_r_cut=None, default_r_on=0.0, mode="none"):
super().__init__(nlist, default_r_cut, default_r_on, mode)
params = TypeParameter(
'params', 'particle_types',
TypeParameterDict(k=float, sigma=float, len_keys=2))
"params",
"particle_types",
TypeParameterDict(k=float, sigma=float, len_keys=2),
)
self._add_typeparam(params)
15 changes: 7 additions & 8 deletions example_plugins/pair_plugin/pytest/test_example_pair.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@

# Python implementation of the pair force and energy.
def harm_force_and_energy(dx, k, sigma, r_cut, shift=False):

dr = np.linalg.norm(dx)

if dr >= r_cut:
return np.array([0.0, 0.0, 0.0], dtype=np.float64), 0.0

f = k * (sigma - dr) * np.array(dx, dtype=np.float64) / dr
e = 0.5 * k * (sigma - dr)**2
e = 0.5 * k * (sigma - dr) ** 2
if shift:
e -= 0.5 * k * (r_cut - sigma)**2
e -= 0.5 * k * (r_cut - sigma) ** 2

return f, e

Expand All @@ -39,10 +38,9 @@ def harm_force_and_energy(dx, k, sigma, r_cut, shift=False):


@pytest.mark.parametrize("distance, k, sigma, mode", testdata)
def test_force_and_energy_eval(simulation_factory,
two_particle_snapshot_factory, distance, k,
sigma, mode):

def test_force_and_energy_eval(
simulation_factory, two_particle_snapshot_factory, distance, k, sigma, mode
):
# Build the simulation from the factory fixtures defined in
# hoomd/conftest.py.
sim = simulation_factory(two_particle_snapshot_factory(d=distance))
Expand All @@ -53,7 +51,8 @@ def test_force_and_energy_eval(simulation_factory,

cell = hoomd.md.nlist.Cell(buffer=0.4)
example_pair: hoomd.md.pair.Pair = pair_plugin.pair.ExamplePair(
cell, default_r_cut=sigma, mode=mode)
cell, default_r_cut=sigma, mode=mode
)
example_pair.params[("A", "A")] = dict(k=k, sigma=sigma)
integrator.forces = [example_pair]
integrator.methods = [nve]
Expand Down
2 changes: 1 addition & 1 deletion example_plugins/shape_plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

from . import integrate

__all__ = ['integrate']
__all__ = ["integrate"]
37 changes: 20 additions & 17 deletions example_plugins/shape_plugin/integrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,29 @@ class MySphere(hpmc.integrate.HPMCIntegrator):
_ext_module = _shape_plugin
_cpp_cls = "IntegratorHPMCMonoMySphere"

def __init__(self,
default_d=0.1,
default_a=0.1,
translation_move_probability=0.5,
nselect=4,
kT=1.0):
def __init__(
self,
default_d=0.1,
default_a=0.1,
translation_move_probability=0.5,
nselect=4,
kT=1.0,
):
# initialize base class
super().__init__(default_d, default_a, translation_move_probability,
nselect, kT)

typeparam_shape = TypeParameter('shape',
type_kind='particle_types',
param_dict=TypeParameterDict(
radius=float,
ignore_statistics=False,
orientable=False,
len_keys=1))
super().__init__(
default_d, default_a, translation_move_probability, nselect, kT
)

typeparam_shape = TypeParameter(
"shape",
type_kind="particle_types",
param_dict=TypeParameterDict(
radius=float, ignore_statistics=False, orientable=False, len_keys=1
),
)
self._add_typeparam(typeparam_shape)

@log(category='object', requires_run=True)
@log(category="object", requires_run=True)
def type_shapes(self):
"""list[dict]: Description of shapes in ``type_shapes`` format."""
return super()._return_type_shapes()
2 changes: 1 addition & 1 deletion example_plugins/updater_plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

from hoomd.updater_plugin import update

__all__ = ['update']
__all__ = ["update"]
10 changes: 5 additions & 5 deletions example_plugins/updater_plugin/pytest/test_example_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
# Use pytest decorator to automate testing over the sequence of parameters.
@pytest.mark.parametrize("vel", velocities)
def test_updater(simulation_factory, one_particle_snapshot_factory, vel):

# `one_particle_snapshot_factory` and `simulation_factory` are pytest
# fixtures defined in hoomd/conftest.py. These factories automatically
# handle iterating tests over different CPU and GPU devices.
Expand All @@ -34,7 +33,8 @@ def test_updater(simulation_factory, one_particle_snapshot_factory, vel):

# Add our plugin to the simulation.
updater: operation.Updater = updater_plugin.update.ExampleUpdater(
hoomd.trigger.On(sim.timestep))
hoomd.trigger.On(sim.timestep)
)
sim.operations.updaters.append(updater)

# Test that the initial velocity matches our input.
Expand All @@ -49,6 +49,6 @@ def test_updater(simulation_factory, one_particle_snapshot_factory, vel):
snap = sim.state.get_snapshot()
if snap.communicator.rank == 0:
velocity = snap.particles.velocity[0]
np.testing.assert_array_almost_equal(velocity,
np.array([0.0, 0.0, 0.0]),
decimal=6)
np.testing.assert_array_almost_equal(
velocity, np.array([0.0, 0.0, 0.0]), decimal=6
)
6 changes: 4 additions & 2 deletions example_plugins/updater_plugin/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ def _attach_hook(self):
# initialize the reflected c++ class
if isinstance(self._simulation.device, hoomd.device.CPU):
self._cpp_obj = _updater_plugin.ExampleUpdater(
self._simulation.state._cpp_sys_def, self.trigger)
self._simulation.state._cpp_sys_def, self.trigger
)
else:
self._cpp_obj = _updater_plugin.ExampleUpdaterGPU(
self._simulation.state._cpp_sys_def, self.trigger)
self._simulation.state._cpp_sys_def, self.trigger
)
67 changes: 36 additions & 31 deletions hoomd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
(`hoomd.write.GSD.flush`) when a user's process is terminated. Use
`signal.signal` to adjust this behavior as needed.
"""

import sys
import pathlib
import os
Expand All @@ -46,23 +47,26 @@

# Work around /usr/lib64/slurm/auth_munge.so: undefined symbol: slurm_conf
# error on Purdue Anvil.
if os.environ.get('RCAC_CLUSTER') == 'anvil':
if os.environ.get("RCAC_CLUSTER") == "anvil":
sys.setdlopenflags(os.RTLD_NOW | os.RTLD_GLOBAL)

if ((pathlib.Path(__file__).parent / 'CMakeLists.txt').exists()
and 'SPHINX' not in os.environ):
if (
pathlib.Path(__file__).parent / "CMakeLists.txt"
).exists() and "SPHINX" not in os.environ:
print("It appears that hoomd is being imported from the source directory:")
print(pathlib.Path(__file__).parent)
print()
print("""Compile the package and import from the build directory or install
print(
"""Compile the package and import from the build directory or install
the package and import from the Python environment.
To run pytest, either:
(1) compile then execute `python3 -m pytest <build-directory>/hoomd` or
(2) compile and install. Then, ensuring your current working directory is
outside the hoomd source directory, execute `python3 -m pytest --pyargs hoomd`.
""",
file=sys.stderr)
file=sys.stderr,
)

from hoomd import version
from hoomd import trigger
Expand All @@ -85,6 +89,7 @@
from hoomd import tune
from hoomd import logging
from hoomd import custom

if version.md_built:
from hoomd import md
if version.hpmc_built:
Expand Down Expand Up @@ -122,30 +127,30 @@ def _hoomd_sys_excepthook(type, value, traceback):
pass

__all__ = [
'Box',
'Operations',
'Simulation',
'Snapshot',
'State',
'box',
'communicator',
'custom',
'data',
'device',
'error',
'filter',
'hpmc',
'logging',
'md',
'mesh',
'mpcd',
'operation',
'trigger',
'tune',
'update',
'util',
'variant',
'version',
'wall',
'write',
"Box",
"Operations",
"Simulation",
"Snapshot",
"State",
"box",
"communicator",
"custom",
"data",
"device",
"error",
"filter",
"hpmc",
"logging",
"md",
"mesh",
"mpcd",
"operation",
"trigger",
"tune",
"update",
"util",
"variant",
"version",
"wall",
"write",
]
Loading

0 comments on commit 8c63de3

Please sign in to comment.