<jupyter_start><jupyter_text>Creating the being<jupyter_code># first we need two experiences
system_1 = pyphi.subsystem.Subsystem(network, network_states[0],nodes=network.node_indices)
system_2 = pyphi.subsystem.Subsystem(network, network_states[1],nodes=network.node_indices)

ces_1 = pyphi.compute.ces(system_1)
ces_2 = pyphi.compute.ces(system_2)
def get_unique_causeeffects(links):
    actual_links = []
    for mechanism1, link1 in links.items():
        update_link = True
        for mechanism2, link2 in links.items():
            if (list(link1.keys())[0] == list(link2.keys())[0]) and (
                list(link1.values())[0] < list(link2.values())[0]
            ):
                update_link = False

        if update_link:
            actual_links.append(
                [mechanism1, list(link1.keys())[0], list(link1.values())[0]]
            )

    return [actual_links]


def get_complex_account(ces_1, ces_2):

    transition = pyphi.actual.Transition(
        ces_2.subsystem.network,
        ces_1.subsystem.state,
        ces_2.subsystem.state,
        ces_1.subsystem.node_indices,
        ces_2.subsystem.node_indices,
    )

    mechanisms_1 = list(ces_1.mechanisms)
    mechanisms_2 = list(ces_2.mechanisms)

    # get all actual causes
    causes = get_unique_causeeffects(
            {
                mechanism: {
                    link.purview: link.alpha
                    for link in (
                        transition.find_actual_cause(mechanism, purviews=mechanisms_2),
                    )
                }
                for mechanism in mechanisms_1
            }
        )
    
    effects = get_unique_causeeffects(
            {
                mechanism: {
                    link.purview: link.alpha
                    for link in (
                        transition.find_actual_effect(mechanism, purviews=mechanisms_1),
                    )
                }
                for mechanism in mechanisms_2
            }
        )
    
    cause_chains = cc.get_cause_chains(
        causes,
        1,
        ces_1.subsystem.node_indices,
        ces_2.subsystem.node_indices,
        all_source_subsets=True,
        all_sink_subsets=True,
    )

    effect_chains = cc.get_effect_chains(
        effects,
        0,
        ces_1.subsystem.node_indices, 
        ces_2.subsystem.node_indices,
        all_source_subsets=True,
        all_sink_subsets=True,
        time_restricted_source=False,
    )
    
    return get_process_account(
        cause_chains, effect_chains, ces_1.subsystem.node_indices, ces_2.subsystem.node_indices
    )
get_complex_account(ces_1, ces_2)


cc.get_effect_chains(
    get_unique_causeeffects(effects),
    0,
    (0, 1, 2, 3, 4), 
    (0, 1, 2, 3, 4),
    all_source_subsets=True,
    all_sink_subsets=True,
    time_restricted_source=False,
)
effects
effects)
actual_links = dict()
for purview1, link1 in causes.items():
    update_link = True
    for purview2, link2 in causes.items():
        if (list(link1.keys())[0] == list(link2.keys())[0]) and (
            list(link1.values())[0] < list(link2.values())[0]
        ):
            update_link = False

    if update_link:
        actual_links.update(link1)
actual_links
get_process_irreducibility(
    cause_chains, effect_chains, (0,1,2,3), (0,1,2,3), k=3, only_subsets=True
)
get_process_irreducibility(
    cause_chains, effect_chains, (0,1,2,3), (0,1,2,3), k=3, only_subsets=False
)
all_subs = list(pyphi.utils.powerset(network.node_indices, nonempty=True))

account_irreducibility_T = {
    (source, sink): get_process_irreducibility(
        cause_chains, effect_chains, source, sink, only_subsets=True
    )
    for source, sink in tqdm(product(
        all_subs,
        all_subs,
    ),total=len(all_subs)**2)
}
irreducible_processes_T = {endpoints: process for endpoints, process in account_irreducibility_T.items() if process['irreducibility']>0}
all_subs = list(pyphi.utils.powerset(network.node_indices, nonempty=True))

account_irreducibility_F = {
    (source, sink): get_process_irreducibility(
        cause_chains, effect_chains, source, sink, only_subsets=False
    )
    for source, sink in tqdm(product(
        all_subs,
        all_subs,
    ),total=len(all_subs)**2)
}
irreducible_processes_F = {endpoints: process for endpoints, process in account_irreducibility_F.items() if process['irreducibility']>0}
subsets = irreducible_processes_T.keys()
parts = irreducible_processes_F.keys()
only_subsets = [k for k in subsets if k not in parts]
only_parts = [k for k in parts if k not in subsets]
irreducible_processes_T[only_subsets[0]]
account_irreducibility_F[only_subsets[0]]
irreducible_processes_F[only_parts[0]]
account_irreducibility_T[only_parts[0]]
only_subsets
only_parts
print([len(p) for p in list(pyphi.partition.partition_types['k_partition_nonempty']((1,2,3,4), 4))])
get_process_irreducibility(
    cause_chains, effect_chains, (0,1), (0,1), k=3, only_subsets=False
)
get_process_irreducibility(
    cause_chains, effect_chains, (0,1), (0,1), k=3, only_subsets=True
)
source = (1,2)
sink = (2,3)

connectedness = get_subprocess(cause_chains, effect_chains, (source, sink))[
        "connectedness"
    ]

irreducibility = np.inf
MIP = (source, sink)
k = max([len(source), len(sink)])


for source_partition, sink_partition in product(
    list(pyphi.partition.partition_types['k_partition_nonempty'](source, k)), #
    list(pyphi.partition.partition_types['k_partition_nonempty'](sink, k)), #
):
    if (len(source_partition)>1 or len(sink_partition)>1):
        part_cause_chains = []
        part_effect_chains = []
        for source_part, sink_part in product(source_partition, sink_partition):
            part_cause_chains.extend(filter_cause_chains(cause_chains, (source_part, sink_part)))
            part_effect_chains.extend(filter_effect_chains(effect_chains, (source_part, sink_part)))

        # then, we compute the subprocess' connectedness by summing the bundle strength of the remaining cause and effect chains.
        part_connectedness = sum(
            [cc.get_bundle_strength(cc.get_bundled_chains(part_cause_chains)), cc.get_bundle_strength(cc.get_bundled_chains(part_effect_chains))]
        )
        
        if connectedness-part_connectedness < irreducibility:
            irreducibility = 0
            MIP = (source_partition, sink_partition)
            
connectedness
filter_cause_chains(cause_chains, (source_part, sink_part))
source = (1,2)
sink = (1,2)
process = get_subprocess(cause_chains, effect_chains, (source, sink))
get_process_account(
    cause_chains,
    effect_chains,
    (0,1,2,3),
    (0,1,2,3),
    hold_process=True
)
get_process_account(
    cause_chains,
    effect_chains,
    (0,),
    (0,),
    hold_process=True
)
get_bundle_informativeness(
    cause_chains, effect_chains, (0,), (0,), process=None
)
process = get_subprocess(cause_chains, effect_chains, ((0,), (0,)))
process
get_bundle_informativeness(
    cause_chains, effect_chains, (0,), (0,), process=process
)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1088560885608856, 'fraction_numerical': 0.02015327845586148, 'mean_word_length': 3.1871657754010694, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '236434', 'license': 'Apache-2.0', 'n_tokens_mistral': 2478, 'n_tokens_neox': 2338, 'n_words': 409, 'path': 'causal-process-Copy1.ipynb', 'repo_name': 'bjorneju/causal_processes', 'size': '7046'}