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

Replace yapf with ruff format. #1956

Merged
merged 4 commits into from
Nov 27, 2024
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
12 changes: 4 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,18 @@ repos:
- --keep-before=#!
- --keep-after=.. include
- repo: https://github.com/kynan/nbstripout
rev: 0.7.1
rev: 0.8.1
hooks:
- id: nbstripout
- repo: https://github.com/google/yapf
rev: 'v0.40.2'
hooks:
- id: yapf
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.8.0'
hooks:
# - id: ruff-format # TODO: enable formatting after all other v5 PRs are merged
# types_or: [python]
- id: ruff-format
types_or: [python]
- id: ruff
types_or: [python]
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v19.1.1
rev: v19.1.4
hooks:
- id: clang-format
types_or: [c, c++, cuda, inc]
Expand Down
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
)
174 changes: 0 additions & 174 deletions hoomd.code-workspace

This file was deleted.

Loading