pyphi.models.cmp.Orderable#

class pyphi.models.cmp.Orderable[source]#

Bases: object

Base mixin for implementing rich object comparisons on phi-objects.

Both __eq__ and order_by need to be implemented on the subclass. The order_by method returns a list of attributes which are compared to implement the ordering.

Subclasses can optionally override is_orderable_with to enforce constraints (for example, AcSystemIrreducibilityAnalysis requires both operands to have the same direction).

Ordering (</>) compares order_by() values exactly, while __eq__ on phi-objects is typically tolerance-aware (see numpy_aware_eq()). Exact ordering keeps selection (max/min/sort) deterministic — with genuine ties handled explicitly by pyphi.resolve_ties — while tolerant equality absorbs float drift in structural comparison. A consequence is that <=/>= (defined as strict ordering or tolerant equality) can both hold for two objects whose values differ by less than the equality tolerance.

order_by()[source]#

Return a list of values to compare for ordering.

The first value in the list has the greatest priority; if the first objects are equal the second object is compared, etc.

Return type:

Any

is_orderable_with(other)[source]#

Whether self and other are mutually orderable.

Default: any two instances are orderable. Override in subclasses that need cross-instance guards.

Parameters:

other (object)

Return type:

bool