Skip to content
Open
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
2 changes: 1 addition & 1 deletion profiling/gprof2dot
Original file line number Diff line number Diff line change
Expand Up @@ -1367,7 +1367,7 @@ class AXEParser(Parser):
attrs[name] = value
return Struct(attrs)

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

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

Expand Down
2 changes: 1 addition & 1 deletion pyphi/metrics/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ def generalized_intrinsic_difference(


def pointwise_intrinsic_differentiation(p):
return -np.log2(p, where=(p > 0))
-np.log2(p, where=(p > 0), out=None)


@measures.register("INTRINSIC_DIFFERENTIATION", asymmetric=True)
Expand Down
42 changes: 21 additions & 21 deletions test/test_big_phi_robust.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,17 +175,17 @@ def test_sia_standard_example_has_repertoires(self, s):
# Check cause repertoire exists and has required attributes
assert result.cause is not None, "SIA missing cause repertoire"
assert hasattr(result.cause, "phi"), "Cause RIA missing phi attribute"
assert hasattr(
result.cause, "mechanism"
), "Cause RIA missing mechanism attribute"
assert hasattr(result.cause, "mechanism"), (
"Cause RIA missing mechanism attribute"
)
assert hasattr(result.cause, "purview"), "Cause RIA missing purview attribute"

# Check effect repertoire exists and has required attributes
assert result.effect is not None, "SIA missing effect repertoire"
assert hasattr(result.effect, "phi"), "Effect RIA missing phi attribute"
assert hasattr(
result.effect, "mechanism"
), "Effect RIA missing mechanism attribute"
assert hasattr(result.effect, "mechanism"), (
"Effect RIA missing mechanism attribute"
)
assert hasattr(result.effect, "purview"), "Effect RIA missing purview attribute"

def test_sia_standard_example_has_system_state(self, s):
Expand Down Expand Up @@ -242,9 +242,9 @@ def test_sia_standard_example_partition_type(self, s):

# System has phi > 0, so should have non-null partition
assert result.phi > 0, "Standard example should have phi > 0"
assert not isinstance(
result.partition, NullCut
), "Irreducible system has NullCut partition"
assert not isinstance(result.partition, NullCut), (
"Irreducible system has NullCut partition"
)

def test_reducible_system_has_null_partition(self, reducible):
"""Reducible system should have null partition.
Expand All @@ -254,12 +254,12 @@ def test_reducible_system_has_null_partition(self, reducible):
"""
result = reducible.sia()

assert isinstance(
result, NullSystemIrreducibilityAnalysis
), "Reducible system should return NullSIA"
assert isinstance(
result.partition, NullCut
), "Reducible system should have NullCut partition"
assert isinstance(result, NullSystemIrreducibilityAnalysis), (
"Reducible system should return NullSIA"
)
assert isinstance(result.partition, NullCut), (
"Reducible system should have NullCut partition"
)
assert result.phi == 0.0, "Reducible system should have phi=0"

def test_empty_subsystem_has_null_partition(self, s_empty):
Expand All @@ -270,12 +270,12 @@ def test_empty_subsystem_has_null_partition(self, s_empty):
"""
result = s_empty.sia()

assert isinstance(
result, NullSystemIrreducibilityAnalysis
), "Empty subsystem should return NullSIA"
assert isinstance(
result.partition, NullCut
), "Empty subsystem should have NullCut partition"
assert isinstance(result, NullSystemIrreducibilityAnalysis), (
"Empty subsystem should return NullSIA"
)
assert isinstance(result.partition, NullCut), (
"Empty subsystem should have NullCut partition"
)
assert result.phi == 0.0, "Empty subsystem should have phi=0"


Expand Down
24 changes: 12 additions & 12 deletions test/test_iit4_robust.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ def test_phi_structure_has_distinctions_attribute(self, example_name):
subsystem = EXAMPLES["subsystem"][example_name]()
result = new_big_phi.phi_structure(subsystem)

assert hasattr(
result, "distinctions"
), f"PhiStructure for '{example_name}' missing 'distinctions' attribute"
assert hasattr(result, "distinctions"), (
f"PhiStructure for '{example_name}' missing 'distinctions' attribute"
)

@pytest.mark.parametrize(
"example_name",
Expand Down Expand Up @@ -227,9 +227,9 @@ def test_phi_structure_has_relations_attribute(self, example_name):
subsystem = EXAMPLES["subsystem"][example_name]()
result = new_big_phi.phi_structure(subsystem)

assert hasattr(
result, "relations"
), f"PhiStructure for '{example_name}' missing 'relations' attribute"
assert hasattr(result, "relations"), (
f"PhiStructure for '{example_name}' missing 'relations' attribute"
)

@pytest.mark.parametrize(
"example_name",
Expand All @@ -255,9 +255,9 @@ def test_phi_structure_distinctions_are_non_empty(self, example_name):
subsystem = EXAMPLES["subsystem"][example_name]()
result = new_big_phi.phi_structure(subsystem)

assert hasattr(
result, "distinctions"
), "PhiStructure missing distinctions attribute"
assert hasattr(result, "distinctions"), (
"PhiStructure missing distinctions attribute"
)

distinctions = result.distinctions
assert distinctions is not None, (
Expand Down Expand Up @@ -310,9 +310,9 @@ def test_distinctions_have_mechanism_attribute(self):

# Check each distinction has a mechanism
for i, distinction in enumerate(concepts):
assert hasattr(
distinction, "mechanism"
), f"Distinction {i} missing 'mechanism' attribute"
assert hasattr(distinction, "mechanism"), (
f"Distinction {i} missing 'mechanism' attribute"
)

def test_distinctions_mechanisms_are_within_subsystem(self):
"""Distinction mechanisms should be subsets of subsystem nodes.
Expand Down
48 changes: 24 additions & 24 deletions test/test_invariants.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,21 +156,21 @@ def test_sia_partition_attribute_consistency(self, s, micro_s, reducible):
# Irreducible systems with phi > 0 should have non-null partitions
s_result = s.sia()
if s_result.phi > 0:
assert not isinstance(
s_result.partition, NullCut
), "System with phi > 0 has NullCut partition (should have real partition)"
assert not isinstance(s_result.partition, NullCut), (
"System with phi > 0 has NullCut partition (should have real partition)"
)

micro_result = micro_s.sia()
if micro_result.phi > 0:
assert not isinstance(
micro_result.partition, NullCut
), "System with phi > 0 has NullCut partition (should have real partition)"
assert not isinstance(micro_result.partition, NullCut), (
"System with phi > 0 has NullCut partition (should have real partition)"
)

# Reducible system should have null partition
reducible_result = reducible.sia()
assert isinstance(
reducible_result.partition, NullCut
), "Reducible system should have NullCut partition"
assert isinstance(reducible_result.partition, NullCut), (
"Reducible system should have NullCut partition"
)

def test_partition_reduces_or_maintains_phi(self, s, micro_s):
"""Partitioned system cannot have more phi than unpartitioned.
Expand Down Expand Up @@ -220,9 +220,9 @@ def test_selfloop_phi_depends_on_config(self, noisy_selfloop_single):
# With config disabled, phi should be 0
with config.override(SINGLE_MICRO_NODES_WITH_SELFLOOPS_HAVE_PHI=False):
result_disabled = noisy_selfloop_single.sia()
assert (
result_disabled.phi == 0.0
), "Expected phi=0 when SINGLE_MICRO_NODES_WITH_SELFLOOPS_HAVE_PHI=False"
assert result_disabled.phi == 0.0, (
"Expected phi=0 when SINGLE_MICRO_NODES_WITH_SELFLOOPS_HAVE_PHI=False"
)

# With config enabled and EMD, phi should be > 0
with config.override(
Expand Down Expand Up @@ -251,9 +251,9 @@ def test_cache_clearing_option(self, s):
CACHE_REPERTOIRES=True,
):
_ = s.sia()
assert (
s._repertoire_cache.cache
), "Cache should have entries when clearing is disabled"
assert s._repertoire_cache.cache, (
"Cache should have entries when clearing is disabled"
)

# Test with cache clearing enabled
with config.override(
Expand All @@ -262,9 +262,9 @@ def test_cache_clearing_option(self, s):
CACHE_REPERTOIRES=True,
):
_ = s.sia()
assert (
not s._repertoire_cache.cache
), "Cache should be empty when clearing is enabled"
assert not s._repertoire_cache.cache, (
"Cache should be empty when clearing is enabled"
)


class TestPhiStructureInvariants:
Expand All @@ -291,12 +291,12 @@ def test_phi_structure_has_distinctions(self, example_name):

# Systems that have phi should have distinctions
if hasattr(result, "phi") and result.phi > 0:
assert hasattr(
result, "distinctions"
), f"System '{example_name}' has phi > 0 but no distinctions attribute"
assert (
len(result.distinctions) > 0
), f"System '{example_name}' has phi > 0 but zero distinctions"
assert hasattr(result, "distinctions"), (
f"System '{example_name}' has phi > 0 but no distinctions attribute"
)
assert len(result.distinctions) > 0, (
f"System '{example_name}' has phi > 0 but zero distinctions"
)

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