Skip to content

Commit d8e1b35

Browse files
[pre-commit.ci] auto fixes from pre-commit hooks
1 parent d850646 commit d8e1b35

4 files changed

Lines changed: 81 additions & 75 deletions

File tree

profiling/gprof2dot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1367,7 +1367,7 @@ class AXEParser(Parser):
13671367
attrs[name] = value
13681368
return Struct(attrs)
13691369

1370-
_cg_header_re = re.compile("^Index |" "^-----+ ")
1370+
_cg_header_re = re.compile("^Index |^-----+ ")
13711371

13721372
_cg_footer_re = re.compile(r"^Index\s+Function\s*$")
13731373

test/test_big_phi_robust.py

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -175,17 +175,17 @@ def test_sia_standard_example_has_repertoires(self, s):
175175
# Check cause repertoire exists and has required attributes
176176
assert result.cause is not None, "SIA missing cause repertoire"
177177
assert hasattr(result.cause, "phi"), "Cause RIA missing phi attribute"
178-
assert hasattr(
179-
result.cause, "mechanism"
180-
), "Cause RIA missing mechanism attribute"
178+
assert hasattr(result.cause, "mechanism"), (
179+
"Cause RIA missing mechanism attribute"
180+
)
181181
assert hasattr(result.cause, "purview"), "Cause RIA missing purview attribute"
182182

183183
# Check effect repertoire exists and has required attributes
184184
assert result.effect is not None, "SIA missing effect repertoire"
185185
assert hasattr(result.effect, "phi"), "Effect RIA missing phi attribute"
186-
assert hasattr(
187-
result.effect, "mechanism"
188-
), "Effect RIA missing mechanism attribute"
186+
assert hasattr(result.effect, "mechanism"), (
187+
"Effect RIA missing mechanism attribute"
188+
)
189189
assert hasattr(result.effect, "purview"), "Effect RIA missing purview attribute"
190190

191191
def test_sia_standard_example_has_system_state(self, s):
@@ -242,9 +242,9 @@ def test_sia_standard_example_partition_type(self, s):
242242

243243
# System has phi > 0, so should have non-null partition
244244
assert result.phi > 0, "Standard example should have phi > 0"
245-
assert not isinstance(
246-
result.partition, NullCut
247-
), "Irreducible system has NullCut partition"
245+
assert not isinstance(result.partition, NullCut), (
246+
"Irreducible system has NullCut partition"
247+
)
248248

249249
def test_reducible_system_has_null_partition(self, reducible):
250250
"""Reducible system should have null partition.
@@ -254,12 +254,12 @@ def test_reducible_system_has_null_partition(self, reducible):
254254
"""
255255
result = reducible.sia()
256256

257-
assert isinstance(
258-
result, NullSystemIrreducibilityAnalysis
259-
), "Reducible system should return NullSIA"
260-
assert isinstance(
261-
result.partition, NullCut
262-
), "Reducible system should have NullCut partition"
257+
assert isinstance(result, NullSystemIrreducibilityAnalysis), (
258+
"Reducible system should return NullSIA"
259+
)
260+
assert isinstance(result.partition, NullCut), (
261+
"Reducible system should have NullCut partition"
262+
)
263263
assert result.phi == 0.0, "Reducible system should have phi=0"
264264

265265
def test_empty_subsystem_has_null_partition(self, s_empty):
@@ -270,12 +270,12 @@ def test_empty_subsystem_has_null_partition(self, s_empty):
270270
"""
271271
result = s_empty.sia()
272272

273-
assert isinstance(
274-
result, NullSystemIrreducibilityAnalysis
275-
), "Empty subsystem should return NullSIA"
276-
assert isinstance(
277-
result.partition, NullCut
278-
), "Empty subsystem should have NullCut partition"
273+
assert isinstance(result, NullSystemIrreducibilityAnalysis), (
274+
"Empty subsystem should return NullSIA"
275+
)
276+
assert isinstance(result.partition, NullCut), (
277+
"Empty subsystem should have NullCut partition"
278+
)
279279
assert result.phi == 0.0, "Empty subsystem should have phi=0"
280280

281281

@@ -419,14 +419,18 @@ def _noisy_copy_subsystem(p, state):
419419
Each node copies the other with probability p (LOLI state ordering).
420420
"""
421421
import numpy as np
422-
from pyphi import Network, Subsystem
423-
424-
tpm = np.array([
425-
[1 - p, 1 - p], # (0,0)
426-
[1 - p, p], # (1,0)
427-
[p, 1 - p], # (0,1)
428-
[p, p], # (1,1)
429-
])
422+
423+
from pyphi import Network
424+
from pyphi import Subsystem
425+
426+
tpm = np.array(
427+
[
428+
[1 - p, 1 - p], # (0,0)
429+
[1 - p, p], # (1,0)
430+
[p, 1 - p], # (0,1)
431+
[p, p], # (1,1)
432+
]
433+
)
430434
cm = np.array([[0, 1], [1, 0]])
431435
network = Network(tpm, cm=cm, node_labels=["A", "B"])
432436
return Subsystem(network, state)
@@ -438,7 +442,8 @@ def test_phi_capped_by_ii(self):
438442
so ii(s) ≈ 0.644 caps phi below GID(MIP).
439443
"""
440444
from pyphi.direction import Direction
441-
from pyphi.new_big_phi import sia, system_intrinsic_information
445+
from pyphi.new_big_phi import sia
446+
from pyphi.new_big_phi import system_intrinsic_information
442447

443448
subsystem = self._noisy_copy_subsystem(0.8, (1, 1))
444449
with config.override(**self.II_CONFIG):
@@ -494,9 +499,7 @@ def test_gid_distance_unaffected(self, s):
494499

495500
# Default config uses GENERALIZED_INTRINSIC_DIFFERENCE
496501
result = sia(s)
497-
assert float(result.phi) == pytest.approx(
498-
EXPECTED_PHI_VALUES["s"], abs=1e-9
499-
)
502+
assert float(result.phi) == pytest.approx(EXPECTED_PHI_VALUES["s"], abs=1e-9)
500503

501504

502505
# ============================================================================
@@ -522,7 +525,9 @@ class TestPaperExamples:
522525
def _monad_subsystem(p):
523526
"""Single-node system that stays in current state with probability p."""
524527
import numpy as np
525-
from pyphi import Network, Subsystem
528+
529+
from pyphi import Network
530+
from pyphi import Subsystem
526531

527532
tpm = np.array([[1 - p], [p]])
528533
cm = np.array([[1]])
@@ -536,6 +541,7 @@ def test_monad_intrinsic_information(self):
536541
The paper reports φ_s = 0.427 (Figure 2C).
537542
"""
538543
import numpy as np
544+
539545
from pyphi.new_big_phi import system_intrinsic_information
540546

541547
p = 0.744
@@ -557,17 +563,17 @@ def test_monad_intrinsic_information(self):
557563
"p,i_diff_expected,i_spec_expected",
558564
[
559565
(0.744, 0.426625, 0.426591), # crossover point (Figure 2C)
560-
(0.9, 0.152003, 0.763197), # high determinism
561-
(0.6, 0.736966, 0.157821), # high noise
566+
(0.9, 0.152003, 0.763197), # high determinism
567+
(0.6, 0.736966, 0.157821), # high noise
562568
],
563569
)
564570
def test_monad_i_diff_i_spec_tradeoff(self, p, i_diff_expected, i_spec_expected):
565571
"""Verify i_diff and i_spec values across the tradeoff curve (Figure 2C).
566572
567573
i_diff = -log2(p), i_spec = p*log2(2p) for a monad in its ON state.
568574
"""
569-
import numpy as np
570-
from pyphi import direction, metrics
575+
from pyphi import direction
576+
from pyphi import metrics
571577
from pyphi.new_big_phi import system_intrinsic_information
572578

573579
subsystem = self._monad_subsystem(p)

test/test_iit4_robust.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,9 @@ def test_phi_structure_has_distinctions_attribute(self, example_name):
195195
subsystem = EXAMPLES["subsystem"][example_name]()
196196
result = new_big_phi.phi_structure(subsystem)
197197

198-
assert hasattr(
199-
result, "distinctions"
200-
), f"PhiStructure for '{example_name}' missing 'distinctions' attribute"
198+
assert hasattr(result, "distinctions"), (
199+
f"PhiStructure for '{example_name}' missing 'distinctions' attribute"
200+
)
201201

202202
@pytest.mark.parametrize(
203203
"example_name",
@@ -227,9 +227,9 @@ def test_phi_structure_has_relations_attribute(self, example_name):
227227
subsystem = EXAMPLES["subsystem"][example_name]()
228228
result = new_big_phi.phi_structure(subsystem)
229229

230-
assert hasattr(
231-
result, "relations"
232-
), f"PhiStructure for '{example_name}' missing 'relations' attribute"
230+
assert hasattr(result, "relations"), (
231+
f"PhiStructure for '{example_name}' missing 'relations' attribute"
232+
)
233233

234234
@pytest.mark.parametrize(
235235
"example_name",
@@ -255,9 +255,9 @@ def test_phi_structure_distinctions_are_non_empty(self, example_name):
255255
subsystem = EXAMPLES["subsystem"][example_name]()
256256
result = new_big_phi.phi_structure(subsystem)
257257

258-
assert hasattr(
259-
result, "distinctions"
260-
), "PhiStructure missing distinctions attribute"
258+
assert hasattr(result, "distinctions"), (
259+
"PhiStructure missing distinctions attribute"
260+
)
261261

262262
distinctions = result.distinctions
263263
assert distinctions is not None, (
@@ -310,9 +310,9 @@ def test_distinctions_have_mechanism_attribute(self):
310310

311311
# Check each distinction has a mechanism
312312
for i, distinction in enumerate(concepts):
313-
assert hasattr(
314-
distinction, "mechanism"
315-
), f"Distinction {i} missing 'mechanism' attribute"
313+
assert hasattr(distinction, "mechanism"), (
314+
f"Distinction {i} missing 'mechanism' attribute"
315+
)
316316

317317
def test_distinctions_mechanisms_are_within_subsystem(self):
318318
"""Distinction mechanisms should be subsets of subsystem nodes.

test/test_invariants.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -158,21 +158,21 @@ def test_sia_partition_attribute_consistency(self, s, micro_s, reducible):
158158
# Irreducible systems with phi > 0 should have non-null partitions
159159
s_result = s.sia()
160160
if s_result.phi > 0:
161-
assert not isinstance(
162-
s_result.partition, NullCut
163-
), "System with phi > 0 has NullCut partition (should have real partition)"
161+
assert not isinstance(s_result.partition, NullCut), (
162+
"System with phi > 0 has NullCut partition (should have real partition)"
163+
)
164164

165165
micro_result = micro_s.sia()
166166
if micro_result.phi > 0:
167-
assert not isinstance(
168-
micro_result.partition, NullCut
169-
), "System with phi > 0 has NullCut partition (should have real partition)"
167+
assert not isinstance(micro_result.partition, NullCut), (
168+
"System with phi > 0 has NullCut partition (should have real partition)"
169+
)
170170

171171
# Reducible system should have null partition
172172
reducible_result = reducible.sia()
173-
assert isinstance(
174-
reducible_result.partition, NullCut
175-
), "Reducible system should have NullCut partition"
173+
assert isinstance(reducible_result.partition, NullCut), (
174+
"Reducible system should have NullCut partition"
175+
)
176176

177177
def test_partition_reduces_or_maintains_phi(self, s, micro_s):
178178
"""Partitioned system cannot have more phi than unpartitioned.
@@ -222,9 +222,9 @@ def test_selfloop_phi_depends_on_config(self, noisy_selfloop_single):
222222
# With config disabled, phi should be 0
223223
with config.override(SINGLE_MICRO_NODES_WITH_SELFLOOPS_HAVE_PHI=False):
224224
result_disabled = noisy_selfloop_single.sia()
225-
assert (
226-
result_disabled.phi == 0.0
227-
), "Expected phi=0 when SINGLE_MICRO_NODES_WITH_SELFLOOPS_HAVE_PHI=False"
225+
assert result_disabled.phi == 0.0, (
226+
"Expected phi=0 when SINGLE_MICRO_NODES_WITH_SELFLOOPS_HAVE_PHI=False"
227+
)
228228

229229
# With config enabled and EMD, phi should be > 0
230230
with config.override(
@@ -253,9 +253,9 @@ def test_cache_clearing_option(self, s):
253253
CACHE_REPERTOIRES=True,
254254
):
255255
_ = s.sia()
256-
assert (
257-
s._repertoire_cache.cache
258-
), "Cache should have entries when clearing is disabled"
256+
assert s._repertoire_cache.cache, (
257+
"Cache should have entries when clearing is disabled"
258+
)
259259

260260
# Test with cache clearing enabled
261261
with config.override(
@@ -264,9 +264,9 @@ def test_cache_clearing_option(self, s):
264264
CACHE_REPERTOIRES=True,
265265
):
266266
_ = s.sia()
267-
assert (
268-
not s._repertoire_cache.cache
269-
), "Cache should be empty when clearing is enabled"
267+
assert not s._repertoire_cache.cache, (
268+
"Cache should be empty when clearing is enabled"
269+
)
270270

271271

272272
class TestPhiStructureInvariants:
@@ -293,12 +293,12 @@ def test_phi_structure_has_distinctions(self, example_name):
293293

294294
# Systems that have phi should have distinctions
295295
if hasattr(result, "phi") and result.phi > 0:
296-
assert hasattr(
297-
result, "distinctions"
298-
), f"System '{example_name}' has phi > 0 but no distinctions attribute"
299-
assert (
300-
len(result.distinctions) > 0
301-
), f"System '{example_name}' has phi > 0 but zero distinctions"
296+
assert hasattr(result, "distinctions"), (
297+
f"System '{example_name}' has phi > 0 but no distinctions attribute"
298+
)
299+
assert len(result.distinctions) > 0, (
300+
f"System '{example_name}' has phi > 0 but zero distinctions"
301+
)
302302

303303
@pytest.mark.parametrize("example_name", ["basic", "fig4"])
304304
def test_phi_structure_has_relations(self, example_name):

0 commit comments

Comments
 (0)