Getting started#
Download this page as a Jupyter notebook
This page installs PyPhi and then walks through a complete computation end to end: build a small substrate from the IIT 4.0 paper, analyze it in a chosen state, read off the integrated information \(\varphi_s\) and the associated \(\Phi\)-structure, and save the result to disk. After installing, the walkthrough takes about ten minutes.
Installation#
Using uv (recommended)#
uv is a fast Python package manager that also installs Python for you. Install it with:
# macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
# Windows
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
Then install PyPhi. Version 2.0 is out as a release candidate, so until the
final release the version has to be given; a bare pip install pyphi installs
1.2 instead.
uv pip install "pyphi>=2.0.0rc1"
Optional features are available as extras: visualize (plotting), caching
(Redis-backed caches), emd (earth-mover’s-distance measures), xarray
(labeled array export), parquet (parquet files, including saved sweep and
optimization results), cluster (Dask-based cluster execution), and mcp
(the MCP server for AI assistants). Install one or more with, e.g.:
uv pip install "pyphi[visualize,emd]>=2.0.0rc1"
To install the latest development version:
uv pip install "git+https://github.com/wmayner/pyphi@main"
Using pip#
pip install "pyphi>=2.0.0rc1" # 2.0 release candidate
pip install "git+https://github.com/wmayner/pyphi@main" # latest development version
Your first computation#
Start by importing the package. Turning off the progress bars keeps the output readable here; leave them on for real computations, where they are helpful.
import pyphi
pyphi.config.progress_bars = False
Build a substrate#
A Substrate is a set of interacting units defined by a
transition probability matrix and a connectivity matrix. PyPhi ships the
example systems used in the IIT literature; we will use the three-unit network
the IIT 4.0 paper introduces the theory with (Albantakis et al. 2023, Fig 1A) —
three units A, B, and C, each a noisy logistic function of its inputs.
substrate = pyphi.examples.iit4_2023_fig1a_substrate()
substrate
| Units | A, B, C |
|---|---|
| State space | binary |
| A | B | C | |
|---|---|---|---|
| A | 1 | 1 | 1 |
| B | 1 | 1 | · |
| C | · | 1 | 1 |
| state | A | B | C |
|---|---|---|---|
| (0,0,0) | 0.119203 | 0.768525 | 0.167982 |
| (1,0,0) | 0.026597 | 0.998887 | 0.5 |
| (0,1,0) | 0.973403 | 0.401312 | 0.167982 |
| (1,1,0) | 0.880797 | 0.994514 | 0.5 |
| (0,0,1) | 0.119203 | 0.0054863 | 0.5 |
| (1,0,1) | 0.026597 | 0.598688 | 0.832018 |
| (0,1,1) | 0.973403 | 0.00111254 | 0.5 |
| (1,1,1) | 0.880797 | 0.231475 | 0.832018 |
The connectivity matrix shows which units influence which, and the transition probability matrix gives the probability that each unit turns on given the current state of the system. Note the probabilities are strictly between 0 and 1: the network is probabilistic, not deterministic.
Analyze a state#
Integrated information is a property of a substrate in a particular state. We
use the state analyzed in the paper — A off, B and C on — ordered
(A, B, C), and hand it, together with the substrate, to
analyze().
state = (0, 1, 1)
analysis = pyphi.analyze(substrate, state)
analysis
| Φ | 4.36567 |
|---|---|
| φs | 0.133873 |
| Distinctions | 6 |
| Σφd | 1.448 |
| Relations | 45 |
| Σφr | 2.91768 |
| Mechanism | φd | Cause purview | Effect purview |
|---|---|---|---|
| a | 0.42835 | B | BC |
| B | 0.523043 | C | a |
| aB | 0.193358 | B | aB |
| aC | 0.0902052 | a | B |
| BC | 0.141602 | a | B |
| aBC | 0.0714404 | aB | aB |
| Units | A,B,C |
|---|---|
| Current state | (0, 1, 1) |
| Specified cause state | (1, 0, 0) |
| Specified effect state | (1, 0, 0) |
| MIP | 2 parts: {AB,C} |
| ii(s) | 0.718749 |
That single call runs the whole analysis of the three-unit system: it measures the system’s irreducibility, finds its distinctions, and computes their relations.
Read the results#
The scalar analysis.phi is \(\varphi_s\), the system integrated information —
how much the system, as a whole, is irreducible to its parts.
round(analysis.phi, 4)
0.1339
The value is positive: the three units hang together as one system. (It reproduces the value published in the paper’s Fig 1E for this system, 0.13.)
Find the complexes#
Not every subset of units exists as a whole of its own. Subsets compete: among
overlapping candidates, only the one with maximal \(\varphi_s\) exists. Such a
subset is called a complex.
complexes() runs that competition over every
subset:
for complex_ in substrate.complexes(state):
print(complex_.node_indices, round(float(complex_.phi), 4))
(2,) 0.2122
(0, 1) 0.0405
The substrate condenses into two complexes: the single unit C, and the pair
{A, B} — the complex the paper features in Fig 1E, written “aB”. (Its
\(\varphi_s\) here differs from the published value; see the worked example.) Every other candidate, including the full three-unit system we just
analyzed, is excluded by one of these two. This is IIT’s exclusion postulate
in action: \(\varphi_s > 0\) makes a candidate eligible; the competition then
proceeds recursively — the strongest candidate claims its units first, and
the remaining candidates compete over what is left, which is how aB can be a
complex even though the full system’s \(\varphi_s\) is larger.
The Φ-structure#
The richer object is the \(\Phi\)-structure, available as analysis.ces (a
CauseEffectStructure). It is the collection of
distinctions — the irreducible mechanisms the system specifies — together
with the relations among them.
ces = analysis.ces
print("distinctions:", len(ces.distinctions))
print("relations: ", ces.relations.num_relations())
distinctions: 6
relations: 45
Its big_phi attribute is the structure integrated information \(\Phi\), the
summed \(\varphi\) of the distinctions and relations.
round(float(ces.big_phi), 4)
4.3657
Every row of the card that analysis prints is explained in
Read a result.
Save the result#
Analyses can be expensive, so it is worth saving them. save()
writes any PyPhi result object to JSON, and load() reads it back.
pyphi.save(ces, "ces.json")
Where to go next#
That is a full PyPhi computation. From here:
To analyze a network of your own, build a substrate from a transition probability matrix, a weight matrix, or a function per unit.
The worked example follows this same network through the paper’s Figures 1, 2, and 4, reproducing the published numbers.
The theory page What IIT computes explains what these quantities mean and how they are defined.
Deterministic networks have \(\varphi_s = 0\), because they provide themselves no alternatives; The intrinsic-information requirement explains why.