Skip to content

Commit 114f464

Browse files
committed
Black linting
1 parent 0b9c109 commit 114f464

File tree

9 files changed

+38
-26
lines changed

9 files changed

+38
-26
lines changed

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ enabled = true
113113

114114
[dependency-groups]
115115
dev = [
116+
"black>=24.8.0",
116117
"pytest>=7.1.3",
117118
"pytest-cov>=4.0.0",
118-
]
119+
]

src/pylattica/core/basic_controller.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,6 @@ def get_random_site(self, state: SimulationState):
3939
return random.randint(0, state.size - 1)
4040

4141
def instantiate_result(self, starting_state: SimulationState):
42-
return SimulationResult(starting_state=starting_state, max_history=self.max_history)
42+
return SimulationResult(
43+
starting_state=starting_state, max_history=self.max_history
44+
)

src/pylattica/core/neighborhood_builders.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ def get(self, struct: PeriodicStructure, site_class: str = None) -> Neighborhood
146146
site_ids = np.array([s[SITE_ID] for s in all_sites])
147147

148148
# Convert to fractional coordinates for periodic KD-tree
149-
frac_coords = np.array([
150-
struct.lattice.get_fractional_coords(loc) for loc in locations
151-
])
149+
frac_coords = np.array(
150+
[struct.lattice.get_fractional_coords(loc) for loc in locations]
151+
)
152152

153153
# Compute the maximum fractional radius that could correspond to
154154
# the Cartesian cutoff. For non-orthogonal lattices, we need to use
@@ -163,9 +163,7 @@ def get(self, struct: PeriodicStructure, site_class: str = None) -> Neighborhood
163163
dim = struct.lattice.dim
164164

165165
# Build boxsize array: 1.0 for periodic dimensions, large value for non-periodic
166-
boxsize = np.array([
167-
1.0 if periodic[i] else 1e10 for i in range(dim)
168-
])
166+
boxsize = np.array([1.0 if periodic[i] else 1e10 for i in range(dim)])
169167

170168
# Wrap fractional coordinates to [0, 1) for periodic dimensions
171169
frac_coords_wrapped = frac_coords.copy()
@@ -296,9 +294,9 @@ def get(self, struct: PeriodicStructure, site_class: str = None) -> Neighborhood
296294
site_ids = np.array([s[SITE_ID] for s in all_sites])
297295

298296
# Convert to fractional coordinates for periodic KD-tree
299-
frac_coords = np.array([
300-
struct.lattice.get_fractional_coords(loc) for loc in locations
301-
])
297+
frac_coords = np.array(
298+
[struct.lattice.get_fractional_coords(loc) for loc in locations]
299+
)
302300

303301
# Compute the maximum fractional radius for the outer cutoff.
304302
# Use the maximum stretch factor of the inverse matrix for non-orthogonal lattices.
@@ -311,9 +309,7 @@ def get(self, struct: PeriodicStructure, site_class: str = None) -> Neighborhood
311309
dim = struct.lattice.dim
312310

313311
# Build boxsize array
314-
boxsize = np.array([
315-
1.0 if periodic[i] else 1e10 for i in range(dim)
316-
])
312+
boxsize = np.array([1.0 if periodic[i] else 1e10 for i in range(dim)])
317313

318314
# Wrap fractional coordinates to [0, 1) for periodic dimensions
319315
frac_coords_wrapped = frac_coords.copy()

src/pylattica/core/simulation_result.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ def from_dict(cls, res_dict):
3939
)
4040
# Restore checkpoint if present
4141
if "checkpoint_state" in res_dict and res_dict["checkpoint_state"] is not None:
42-
res._checkpoint_state = SimulationState.from_dict(res_dict["checkpoint_state"])
42+
res._checkpoint_state = SimulationState.from_dict(
43+
res_dict["checkpoint_state"]
44+
)
4345
res._checkpoint_step = res_dict.get("checkpoint_step", 0)
4446

4547
for diff in diffs:
@@ -50,11 +52,18 @@ def from_dict(cls, res_dict):
5052
res._diffs.append(diff) # Bypass add_step to avoid re-checkpointing
5153

5254
# Restore total_steps from serialized data, or compute from diffs + checkpoint
53-
res._total_steps = res_dict.get("total_steps", res._checkpoint_step + len(diffs))
55+
res._total_steps = res_dict.get(
56+
"total_steps", res._checkpoint_step + len(diffs)
57+
)
5458

5559
return res
5660

57-
def __init__(self, starting_state: SimulationState, compress_freq: int = 1, max_history: int = None):
61+
def __init__(
62+
self,
63+
starting_state: SimulationState,
64+
compress_freq: int = 1,
65+
max_history: int = None,
66+
):
5867
"""Initializes a SimulationResult with the specified starting_state.
5968
6069
Parameters
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
from .controller import GameOfLifeController, Life, Seeds, Anneal, Diamoeba, Maze
2-
from .life_phase_set import LIFE_PHASE_SET
2+
from .life_phase_set import LIFE_PHASE_SET
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from ...discrete.phase_set import PhaseSet
22

3-
LIFE_PHASE_SET = PhaseSet(["alive", "dead"])
3+
LIFE_PHASE_SET = PhaseSet(["alive", "dead"])

src/pylattica/structures/square_grid/grid_setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,9 @@ def setup_random_sites(
348348

349349
while num_sites_planted < num_sites_desired:
350350
if total_attempts > 1000 * num_sites_desired:
351-
print(f"Only able to place {num_sites_planted} in {total_attempts} attempts")
351+
print(
352+
f"Only able to place {num_sites_planted} in {total_attempts} attempts"
353+
)
352354
break
353355

354356
rand_site = random.choice(all_sites)

src/pylattica/structures/square_grid/neighborhoods.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ def __init__(self, size: int):
5454
# Generate Von Neumann neighborhood offsets (excluding origin)
5555
points = get_points_in_cube(-size, size + 1, 3)
5656
self._offsets = [
57-
tuple(point) for point in points
57+
tuple(point)
58+
for point in points
5859
if sum(np.abs(p) for p in point) <= size and any(p != 0 for p in point)
5960
]
6061
# Precompute distances for edge weights
6162
self._distances = {
62-
offset: np.sqrt(sum(p**2 for p in offset))
63-
for offset in self._offsets
63+
offset: np.sqrt(sum(p**2 for p in offset)) for offset in self._offsets
6464
}
6565
# Cache for grid size (computed once per structure)
6666
self._cached_n = None
@@ -70,8 +70,8 @@ def _get_grid_size(self, struct: PeriodicStructure) -> int:
7070
"""Infer grid size n from structure (cached)."""
7171
n_sites = len(struct.site_ids)
7272
if n_sites != self._cached_n_sites:
73-
n = int(round(n_sites ** (1/3)))
74-
if n ** 3 != n_sites:
73+
n = int(round(n_sites ** (1 / 3)))
74+
if n**3 != n_sites:
7575
raise ValueError(f"Structure has {n_sites} sites, not a perfect cube.")
7676
self._cached_n = n
7777
self._cached_n_sites = n_sites

src/pylattica/visualization/square_grid_artist_2D.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ def _draw_image(self, state: SimulationState, **kwargs):
6262

6363
for phase in legend_order:
6464
color = legend.get(phase)
65-
p_col_start = state_size * cell_size + legend_border_width + legend_hoffset
65+
p_col_start = (
66+
state_size * cell_size + legend_border_width + legend_hoffset
67+
)
6668
p_row_start = count * cell_size + legend_voffset
6769
for p_x in range(p_col_start, p_col_start + cell_size):
6870
for p_y in range(p_row_start, p_row_start + cell_size):

0 commit comments

Comments
 (0)