"""Produce the iit:result/feedforward-3node canon entry.

A three-unit feedforward chain A -> B -> C: A has no inputs and is maximally
noisy (p = 1/2 either way), B copies A, C copies B. The substrate is not
strongly connected, so a partition cutting in the (absent) feedback direction
makes no difference and phi_s = 0.

Run with any install of PyPhi 2.0:

    uv run python canon/feedforward-3node.py
"""

from importlib.metadata import version

import numpy as np
import pyphi

# State-by-node TPM, little-endian state order (row index = A + 2B + 4C):
# P(unit ON at t+1 | state at t). A is a coin flip, B copies A, C copies B.
tpm = np.array(
    [[0.5, float(a), float(b)] for c in (0, 1) for b in (0, 1) for a in (0, 1)]
)

cm = np.array(
    [
        [0, 1, 0],  # A -> B
        [0, 0, 1],  # B -> C
        [0, 0, 0],
    ]
)

state = (0, 0, 0)

if __name__ == "__main__":
    substrate = pyphi.Substrate(tpm, cm=cm, node_labels=("A", "B", "C"))
    system = pyphi.System.from_substrate(substrate, state)
    sia = system.sia()
    print("pyphi", version("pyphi"))
    print("state", state)
    print("phi_s", sia.phi)
    print("partition", sia.partition)
