GithubHelp home page GithubHelp logo

wmayner / pyphi Goto Github PK

View Code? Open in Web Editor NEW
366.0 37.0 98.0 22.77 MB

A toolbox for integrated information theory.

Home Page: https://journals.plos.org/ploscompbiol/article?id=10.1371/journal.pcbi.1006343

License: Other

Python 99.84% Shell 0.01% Makefile 0.15%
causality information neuroscience integrated-information modeling causation

pyphi's Introduction

PyPhi logo

Documentation badge Coveralls.io badge Python versions badge

PyPhi is a Python library for computing integrated information (𝚽), and the associated quantities and objects.

If you use this code, please cite the paper:


Mayner WGP, Marshall W, Albantakis L, Findlay G, Marchman R, Tononi G. (2018) PyPhi: A toolbox for integrated information theory. PLOS Computational Biology 14(7): e1006343. https://doi.org/10.1371/journal.pcbi.1006343


An illustrated tutorial on how Φ is calculated is available as a supplement to the paper.

Usage, Examples, and API documentation

Installation

Set up a Python 3 virtual environment and install with

pip install pyphi

To install the latest development version, which is a work in progress and may have bugs, run:

pip install "git+https://github.com/wmayner/pyphi@develop#egg=pyphi"

Note: this software is only supported on Linux and macOS. However, if you use Windows, you can run it by using the Anaconda Python distribution and installing PyPhi with conda:

conda install -c wmayner pyphi

Detailed installation guide for Mac OS X

See here.

User group

For discussion about the software or integrated information theory in general, you can join the pyphi-users group.

For technical issues with PyPhi or feature requests, please use the issues page.

Contributing

To help develop PyPhi, fork the project on GitHub and install the requirements with

pip install -r requirements.txt

The Makefile defines some tasks to help with development:

make test

runs the unit tests every time you change the source code.

make benchmark

runs performance benchmarks.

make docs

builds the HTML documentation.

Developing on Linux

Make sure you install the C headers for Python 3, SciPy, and NumPy before installing the requirements:

sudo apt-get install python3-dev python3-scipy python3-numpy

Developing on Windows

If you're just looking for an editable install, pip may work better than the conda develop utility included in the conda-build package. When using pip on Windows, the build of pyemd may fail. The simplest solution to this is to obtain pyemd through conda.

conda create -n pyphi_dev
conda activate pyphi_dev
conda install -c wmayner pyemd
cd path/to/local/editable/copy/of/pyphi
pip install -e .

Unfortunately, pip isn't great at managing the DLLs that some packages (especially scipy) rely on. If you have missing DLL errors, try reinstalling the offending package (here, scipy) with conda.

conda activate pyphi_dev
pip uninstall scipy
conda install scipy

Credit

Please cite these papers if you use this code:

Mayner WGP, Marshall W, Albantakis L, Findlay G, Marchman R, Tononi G. (2018) PyPhi: A toolbox for integrated information theory. PLOS Computational Biology 14(7): e1006343. https://doi.org/10.1371/journal.pcbi.1006343

@article{mayner2018pyphi,
  title={PyPhi: A toolbox for integrated information theory},
  author={Mayner, William GP and Marshall, William and Albantakis, Larissa and Findlay, Graham and Marchman, Robert and Tononi, Giulio},
  journal={PLoS Computational Biology},
  volume={14},
  number={7},
  pages={e1006343},
  year={2018},
  publisher={Public Library of Science},
  doi={10.1371/journal.pcbi.1006343},
  url={https://doi.org/10.1371/journal.pcbi.1006343}
}

Albantakis L, Oizumi M, Tononi G (2014). From the Phenomenology to the Mechanisms of Consciousness: Integrated Information Theory 3.0. PLoS Comput Biol 10(5): e1003588. doi: 10.1371/journal.pcbi.1003588.

@article{iit3,
    title={From the Phenomenology to the Mechanisms of Consciousness:
    author={Albantakis, Larissa AND Oizumi, Masafumi AND Tononi, Giulio},
    Integrated Information Theory 3.0},
    journal={PLoS Comput Biol},
    publisher={Public Library of Science},
    year={2014},
    month={05},
    volume={10},
    pages={e1003588},
    number={5},
    doi={10.1371/journal.pcbi.1003588},
    url={http://dx.doi.org/10.1371%2Fjournal.pcbi.1003588}
}

This project is inspired by a previous project written in Matlab by L. Albantakis, M. Oizumi, A. Hashmi, A. Nere, U. Olcese, P. Rana, and B. Shababo.

Correspondence regarding this code and the PyPhi paper should be directed to Will Mayner, at [email protected]. Correspondence regarding the Matlab code and the IIT 3.0 paper should be directed to Larissa Albantakis, PhD, at [email protected].

pyphi's People

Contributors

ajbailey4 avatar albantakis avatar dviggiano avatar grahamfindlay avatar isacdaavid avatar matteograsso avatar renzocom avatar rlmv avatar sanjayankur31 avatar wmayner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyphi's Issues

Couldn't find collections.abc

Hey man,

I am not sure if I did something wrong on my Ubuntu-Server, but I had to add import collections.abc to the file .../pyphi/models/cuts.py.

Cheers,
Dominik

Python 3.8 multiprocessing breaks configuration system with parallelization on macOS

Interactive changes to the configuration are not respected in subprocesses in Python 3.8 on macOS.

This is due to a change introduced in Python 3.8: on macOS, multiprocessing starts processes with spawn by default, instead of fork. The subprocesses no longer receive the Config object from the parent process and create their own, losing the interactive changes.

Relevant discussion on the Python bug tracker: https://bugs.python.org/issue33725

AttributeError: module pytest has no attribute lazy_fixture

hi,

I'm investigating a solution when trying to run test_actual.py

(IIT) [diego@diego test]$ python *actual.py but I get the following error:

Welcome to PyPhi!

If you use PyPhi in your research, please cite the paper:

  Mayner WGP, Marshall W, Albantakis L, Findlay G, Marchman R, Tononi G.
  (2018). PyPhi: A toolbox for integrated information theory.
  PLOS Computational Biology 14(7): e1006343.
  https://doi.org/10.1371/journal.pcbi.1006343

Documentation is available online (or with the built-in `help()` function):
  https://pyphi.readthedocs.io

To report issues, please use the issue tracker on the GitHub repository:
  https://github.com/wmayner/pyphi

For general discussion, you are welcome to join the pyphi-users group:
  https://groups.google.com/forum/#!forum/pyphi-users

To suppress this message, either:
  - Set `WELCOME_OFF: true` in your `pyphi_config.yml` file, or
  - Set the environment variable PYPHI_WELCOME_OFF to any value in your shell:
        export PYPHI_WELCOME_OFF='yes'

Traceback (most recent call last):
  File "/home/diego/anaconda3/envs/IIT/lib/python3.9/site-packages/b/pyphi-feature-iit-4.0/test/test_actual.py", line 99, in <module>
    (pytest.lazy_fixture("background_all_off"), Direction.EFFECT, (0,), (1,), 1),
  File "/home/diego/anaconda3/envs/IIT/lib/python3.9/site-packages/pytest/__init__.py", line 171, in __getattr__
    raise AttributeError(f"module {__name__} has no attribute {name}")
AttributeError: module pytest has no attribute lazy_fixture
(IIT) [diego@diego test]$ 

also to test_json.py:

(IIT) [diego@diego test]$ python *json.py

Welcome to PyPhi!

If you use PyPhi in your research, please cite the paper:

  Mayner WGP, Marshall W, Albantakis L, Findlay G, Marchman R, Tononi G.
  (2018). PyPhi: A toolbox for integrated information theory.
  PLOS Computational Biology 14(7): e1006343.
  https://doi.org/10.1371/journal.pcbi.1006343

Documentation is available online (or with the built-in `help()` function):
  https://pyphi.readthedocs.io

To report issues, please use the issue tracker on the GitHub repository:
  https://github.com/wmayner/pyphi

For general discussion, you are welcome to join the pyphi-users group:
  https://groups.google.com/forum/#!forum/pyphi-users

To suppress this message, either:
  - Set `WELCOME_OFF: true` in your `pyphi_config.yml` file, or
  - Set the environment variable PYPHI_WELCOME_OFF to any value in your shell:
        export PYPHI_WELCOME_OFF='yes'

Traceback (most recent call last):
  File "/home/diego/anaconda3/envs/IIT/lib/python3.9/site-packages/b/pyphi-feature-iit-4.0/test/test_json.py", line 10, in <module>
    from test_actual import transition
  File "/home/diego/anaconda3/envs/IIT/lib/python3.9/site-packages/b/pyphi-feature-iit-4.0/test/test_actual.py", line 99, in <module>
    (pytest.lazy_fixture("background_all_off"), Direction.EFFECT, (0,), (1,), 1),
  File "/home/diego/anaconda3/envs/IIT/lib/python3.9/site-packages/pytest/__init__.py", line 171, in __getattr__
    raise AttributeError(f"module {__name__} has no attribute {name}")
AttributeError: module pytest has no attribute lazy_fixture
(IIT) [diego@diego test]$ 

Error when trying to receive TPM using json

HH,

i have open ipython, done import numpy as np and import pyphi. And then I have done
network = pyphi.network.from_json ('/home/ diego/ NET/network.json')

But when I run network.tpm I get the following error message below:


In [5]: network.tpm
----------------------------------------
AttributeErrorTraceback (most recent call last)
<ipython-input-5-044da6143242> in <module>
----> 1 network.tpm

AttributeError: 'dict' object has no attribute 'tpm'

What am I doing wrong? Should I get the TPM instead of the error message, or not?

Error in Multithreading?

Hey guys,

It seems that pyphi isn't stable anymore. I got a multithreading exception:

Traceback (most recent call last): File "/usr/lib/python3.4/multiprocessing/queues.py", line 242, in _feed obj = ForkingPickler.dumps(obj) File "/usr/lib/python3.4/multiprocessing/reduction.py", line 50, in dumps cls(buf, protocol).dump(obj)

Could you maybe help me with this issue?

Deep Networks

Hi,

Do you have an easy application of this measure to a training Deep NN on TensorFlow or Keras for example? I'd like to see for example how phi evolves during training, if it steadily increases, and which absolute value it achieves.

I'd love to play with it and I bet it would have a huge impact to the spread of interest into IIT.

Thanks for the good work,
Luca

Python3.12: Tests fail

Python 3.12 has landed in Fedora. Rebuilding pyphi with Python 3.12 results in the following test failure:

=================================== FAILURES ===================================
___________________________ [doctest] 2014paper.rst ____________________________
549 
550 Figure 12
551 ~~~~~~~~~
552 
553 **Assessing the integrated conceptual information Φ of a constellation C.**
554 
555 To calculate :math:`\Phi^{\textrm{MIP}}` for a candidate set, we use the
556 function |compute.sia()|:
557 
558     >>> sia = pyphi.compute.sia(subsystem)
UNEXPECTED EXCEPTION: ValueError("Unable to configure handler 'queue'")
Traceback (most recent call last):
  File "/usr/lib64/python3.12/doctest.py", line 1357, in __run
    exec(compile(example.source, filename, "single",
  File "<doctest 2014paper.rst[78]>", line 1, in <module>
  File "/builddir/build/BUILD/pyphi-1.2.1/pyphi/compute/subsystem.py", line 323, in sia
    return _sia(_sia_cache_key(subsystem), subsystem)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/builddir/build/BUILD/pyphi-1.2.1/pyphi/memory.py", line 35, in wrapper
    return f(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/decorator.py", line 232, in fun
    return caller(func, *(extras + args), **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/builddir/build/BUILD/pyphi-1.2.1/pyphi/utils.py", line 213, in time_annotated
    result = func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^
  File "/builddir/build/BUILD/pyphi-1.2.1/pyphi/compute/subsystem.py", line 262, in _sia
    unpartitioned_ces = _ces(subsystem)
                        ^^^^^^^^^^^^^^^
  File "/builddir/build/BUILD/pyphi-1.2.1/pyphi/compute/subsystem.py", line 208, in _ces
    return ces(subsystem, parallel=config.PARALLEL_CUT_EVALUATION)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/decorator.py", line 232, in fun
    return caller(func, *(extras + args), **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/builddir/build/BUILD/pyphi-1.2.1/pyphi/utils.py", line 213, in time_annotated
    result = func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^
  File "/builddir/build/BUILD/pyphi-1.2.1/pyphi/compute/subsystem.py", line 96, in ces
    return CauseEffectStructure(engine.run(parallel or
                                ^^^^^^^^^^^^^^^^^^^^^^
  File "/builddir/build/BUILD/pyphi-1.2.1/pyphi/compute/parallel.py", line 331, in run
    return self.run_parallel()
           ^^^^^^^^^^^^^^^^^^^
  File "/builddir/build/BUILD/pyphi-1.2.1/pyphi/compute/parallel.py", line 266, in run_parallel
    r.reraise()
  File "/builddir/build/BUILD/pyphi-1.2.1/pyphi/compute/parallel.py", line 64, in reraise
    raise self.exception.with_traceback(self.tb.as_traceback())
  File "/builddir/build/BUILD/pyphi-1.2.1/pyphi/compute/parallel.py", line 174, in worker
    configure_worker_logging(log_queue)
    ^^^^^^^^^^^^^^^^^
  File "/builddir/build/BUILD/pyphi-1.2.1/pyphi/compute/parallel.py", line 361, in configure_worker_logging
    logging.config.dictConfig(
      ^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.12/logging/config.py", line 912, in dictConfig
    dictConfigClass(config).configure()
      ^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.12/logging/config.py", line 588, in configure
    raise ValueError('Unable to configure handler '
    ^^^^^^^^^^^^^^^^^
ValueError: Unable to configure handler 'queue'
/builddir/build/BUILD/pyphi-1.2.1/docs/examples/2014paper.rst:558: UnexpectedException

Version 1.2.1 has never been released

Neither on GitHub nor on PyPI has 1.2.1 officially been released. A tag on GitHub is all that points to version 1.2.1. Please consider releasing 1.2.1 on at least PyPI.

Applying IIT to the Game of Life

https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life

When a cell is alive, it has 140 possible predecessor patterns, if it is dead, 372.

Can one apply IIT to visualize phi values and subject boundaries?

I found one of your previous publications which applied IIT to elementary cellular automata: https://www.mdpi.com/1099-4300/17/8/5472

Are you aware of anyone who considered the 2D, 3D or even smooth-case?

Edit: From your answer here I can see that this problem seems to be currently computationally intractable, even in regular systems such as these.

how use to use `subsystem.evaluate_partition`

Hi, I wonder if you can help me? I'm a bit new to this work and API, so this might be a silly question?

I've installed the latest development version, and I'm trying to calculate small phi over different partitions. I run this code,

import pyphi

from pyphi.subsystem import mip_bipartitions

network = pyphi.examples.fig6()
state = (1, 0, 0)
subsystem = pyphi.Subsystem(network, state, range(network.size))
A,B,C = subsystem.node_indices

mechanism = subsystem.node_indices 
purview   = subsystem.node_indices
 
all_bipartitions = mip_bipartitions( mechanism, purview )

partition = all_bipartitions[1]
direction = "|past|" 

Can you help me use the following methods please? I don't understand why I'm getting these erros?

>>> subsystem.evaluate_partition( direction, (A,), (A, B, C) , partition )
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ajay/anaconda3/lib/python3.6/site-packages/pyphi/subsystem.py", line 532, in evaluate_partition
    partitioned_repertoire = self.partitioned_repertoire(direction, partition)
  File "/home/ajay/anaconda3/lib/python3.6/site-packages/pyphi/subsystem.py", line 434, in partitioned_repertoire
    return part1rep * part2rep
TypeError: unsupported operand type(s) for *: 'NoneType' and 'NoneType'
>>> 
>>> subsystem.find_mip( direction, (A,) , (A,B,C) )
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ajay/anaconda3/lib/python3.6/site-packages/pyphi/subsystem.py", line 587, in find_mip
    unpartitioned_repertoire=unpartitioned_repertoire)
  File "/home/ajay/anaconda3/lib/python3.6/site-packages/pyphi/subsystem.py", line 532, in evaluate_partition
    partitioned_repertoire = self.partitioned_repertoire(direction, partition)
  File "/home/ajay/anaconda3/lib/python3.6/site-packages/pyphi/subsystem.py", line 434, in partitioned_repertoire
    return part1rep * part2rep
TypeError: unsupported operand type(s) for *: 'NoneType' and 'NoneType'

I guess my install is OK, as the functions see to be there

>>> subsystem.evaluate_partition
<bound method Subsystem.evaluate_partition of Subsystem((n0, n1, n2))>
>>> subsystem.find_mip
<bound method Subsystem.find_mip of Subsystem((n0, n1, n2))>

Thank you very much :)

atomic_write_yaml() fails to move fresh pyphi_config.yml ?

I encountered this new thing while trying to run the test suite against the iit-4.0 branch, while also excluding the tests I had already found to be anti-sufficient for passing the suite.

It fails to collect test/test_subsystem_phi_max.py before actual testing starts.

py.test --slow -k 'not test foo and not test bar and not test blablabla'

========================================= test session starts ==========================================
platform linux -- Python 3.10.5, pytest-7.1.2, pluggy-1.0.0 -- /usr/bin/python
cachedir: .pytest_cache
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/home/isaac/pyphi/.hypothesis/examples')
rootdir: /home/isaac/pyphi, configfile: pytest.ini, testpaths: pyphi, test, docs
plugins: hypothesis-6.47.2, lazy-fixture-0.6.3, anyio-3.6.1
collected 641 items / 1 error                                                                          

=======================ERRORS =========================
_________ERROR collecting test/test_subsystem_phi_max.py ________

test/test_subsystem_phi_max.py:16: in <module>
    with config.override(REPERTOIRE_DISTANCE="EMD"):
pyphi/conf.py:367: in __enter__
    self.conf.load_dict(self.new_values)
pyphi/conf.py:314: in load_dict
    setattr(self, k, v)
pyphi/conf.py:293: in __setattr__
    super().__setattr__(name, value)
pyphi/conf.py:220: in __set__
    self._callback(obj)
pyphi/conf.py:246: in _callback
    self.on_change(obj)
pyphi/conf.py:275: in wrapper
    func(*args, **kwargs)
pyphi/conf.py:1061: in on_change_global
    atomic_write_yaml(config.snapshot(), PYPHI_MANAGED_CONFIG_PATH)
pyphi/conf.py:1051: in atomic_write_yaml
    Path(f.name).rename(path)
/usr/lib/python3.10/pathlib.py:1234: in rename
    self._accessor.rename(self, target)
E   OSError: [Errno 18] Invalid cross-device link: '/tmp/tmp7jw9h8j6' -> '__pyphi_cache__/config/pyphi_config.yml'
======================================== Hypothesis Statistics =========================================
======================================= short test summary info ========================================
ERROR test/test_subsystem_phi_max.py - OSError: [Errno 18] Invalid cross-device link: '/tmp/tmp7jw9h8...
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
=========================================== 1 error in 0.51s ===========================================

According to the internet, os.rename() can't move files across filesystems, which is the case in my computer (although that doesn't explain why I'm only seeing the error until now):

$ df -h /tmp

Filesystem      Size  Used Avail Use% Mounted on
tmpfs            16G  1.5M   16G   1% /tmp

People suggest doing it in 2 steps: copying, removing. I simply bypassed this by making atomic_write_yaml() write directly to the final path, but I don't know if either solution is "atomic" enough.

Support for different ways of computing phi?

As Max Tegmark pointed out here:
https://www.youtube.com/watch?v=QnEtNC8eFso or
https://journals.plos.org/ploscompbiol/article?id=10.1371/journal.pcbi.1005123
there are many alternative ways of computing phi (he gives 420). For example you can choose how to compute the probability distributions, or which metric to use to compare them. I noticed in pyphi_config.yml that you support changing the distance metric with: MEASURE: "EMD". Do you have some support for other options he talks about? If not do you plan to add them in the future?

Compute relations up to a certain order

It would be good to have a function to compute relations only up to a certain order (perhaps an optional argument in the pyphi.relations.all_relations function or a separate function).

Breaking changes in dependencies

While trying to do a clean install, I noticed that both scipy and numpy have breaking changes and the versions in setup.py are not upper-bounded.

I was able to successfully install by installing the following versions:

scipy =1.2.1
numpy =1.16.2

Error import network.json file in the ipython or python

I'm trying to import network.json as described here Figure 7 (import network.json file) and I get the error below. Would anyone have any idea what I'm probably doing wrong?

>>> network = pyphi.network.from_json('/home/me/network.json')
>>> network.tpm
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'dict' object has no attribute 'tpm'
>>> 

where is PQR cause-effect space on fpga with φ?

Will,
I understand the mailing list might prove more suitable. #32

Where is a simple worked example of PQR using gates on fpga
verilog or VHDL and demonstrating a value for φ

it would be helpful to me if both feedback and feedforward-only demonstrate same output with different φ!

apologies but I find python gets in the way of my initial understanding.

many thanks

concept_caching error

Hey Will, or whoever else :)

I'm trying to get caching working, and I've noticed a curious bug in the following code:

    XOR =  lambda xs: sum(xs) == 1

    nodes = [XOR, XOR, XOR]

    current_state = (1, 0, 0)

    past_state = ((0,))*len(current_state)

    cm = [[1,1,1],
          [1,0,1],
          [1,1,1]]

    tpm = get_tpm(nodes, cm) #(my function for generating a tpm)

    network = pyphi.Network(tpm, current_state, past_state, connectivity_matrix=cm)

    main_complex = pyphi.compute.main_complex(network)

Error:

...
File "/home/josh/.virtualenvs/IITipython3/lib/python3.4/site-packages/pyphi/concept_caching.py", line 276, in __init__
    self.mechanism)
  File "/home/josh/.virtualenvs/IITipython3/lib/python3.4/site-packages/pyphi/concept_caching.py", line 246, in _normalize_mice
    mice.purview, mice.repertoire, normalized_indices)
  File "/home/josh/.virtualenvs/IITipython3/lib/python3.4/site-packages/pyphi/concept_caching.py", line 221, in _normalize_purview_and_repertoire
    purview = sorted(purview)
TypeError: 'NoneType' object is not iterable

This error only occurs when the network isn't fully connected (including self-connections). If you replace the 0 with a 1 in the connection matrix, all works as planned.

I'm using the pyphi version from pip install pyphi.

Any thoughts?

Scalability to large network

Hi, thanks for your great work.
I'm running IIT 4.0 12 nodes 2^12=4096 state-by-state network on Google Colab Pro+ A100 GPU runtime. Please see this for the sample code.
Seems like the code is stack here (sorry, not sure about which of the lines gives the problem).
Is this expected (state matrix too large for computation) or do you think the problem lies in the matrix itself? Thanks!

subsystem_backward = pyphi.Subsystem(
    network,
    state,
    nodes=node_labels,
    backward_tpm=True
)

subsystem_forward = pyphi.Subsystem(
    network,
    state,
    nodes=node_labels
)

`evaluate_cut` running slow ?

Hi @wmayner,

can you give some advice/help why I find it takes much longer to run compute.evaluate_cut compared to simply running compute.big_mip ?

Here's a minimal script you can run, and also a net you can download

https://www.dropbox.com/s/705c2ne4gpj13qo/network_4_nodes_dev_pyphi.json?dl=0

to reproduce it exactly, (but I get the same behaviour for all other subsystems too).


import pyphi
from pyphi.compute.big_phi import evaluate_cut
import json
from random import randint
from time import time

##---------------------------------------------------
# Import net and setup system 
##---------------------------------------------------

import json

path_to_saved_net = "/home/ajay/Downloads/network.json"
with open(path_to_saved_net) as data_file:    
    data = json.load(data_file)

tpm = data['tpm']
cm = data['cm']
state = data['state']

network = pyphi.Network(tpm, connectivity_matrix=cm)
subsystem = pyphi.Subsystem(network, state, range(network.size)) 
#subsystem.node_indices

pyphi.config.CACHE_BIGMIPS = False
pyphi.config.PARALLEL_CUT_EVALUATION = False

##---------------------------------------------------
# Simple Big mip calculation
##---------------------------------------------------

def compute_big_mip(subsystem):
    start = time()
    for i in range (0,100):
        mip = pyphi.compute.big_mip( subsystem ) 
    print(time()-start)


##---------------------------------------------------
# Simple Big mip calculation and a random cut
##---------------------------------------------------

unpartitioned_constellation = pyphi.compute.constellation(subsystem)

all_bipartitions = pyphi.utils.directed_bipartition( subsystem.node_indices )[1:-1] # can be precomputed when the environment is initialized
num_all_directed_bipartitions = len(all_bipartitions) 

def compute_big_mip_and_a_random_cut( subsystem ):
    start = time()
    for t in range (0,100): 
        mip = pyphi.compute.big_mip(subsystem) 
        i = randint(0, num_all_directed_bipartitions-1)
        rand_bipartition = all_bipartitions[ i : i+1 ] # random directed bipartition
        random_cut = [ pyphi.models.cuts.Cut ( bipartition[0], bipartition[1] ) for bipartition in rand_bipartition ] # random_cut
        mip_of_rand_cut = evaluate_cut(subsystem, random_cut[0], unpartitioned_constellation) # pyphi/compute/big_phi.py#L27           
    print(time()-start)

##---------------------------------------------------
# Compare timings 
##---------------------------------------------------

>>> compute_big_mip(subsystem)
10.356880187988281
>>> 
>>> compute_big_mip_and_a_random_cut( subsystem )
39.57922887802124

So my question is why does it take 3 times as long to evaluate a single random cut, compare to evaluating the big_mip for a full system which requires searching over many cuts?

If I can sort this out I'll be able to run some experiments, and can show you how to apply ML here.

Thanks a lot for your help,

Aj

Import error

Hello,
          I am having following import error on Mac m1 silicon chip Pycharm python 3.11.1 & 2.7.18 

 ImportError: cannot import name 'Iterable' from 'collections' (/Library/Frameworks/Python.framework/
 Versions/3.11/lib/python3.11/collections/__init__.py)

 **import pyphi** 

AttributeError: module 'pyphi' has no attribute 'tpm'

I have pyphi 3.6.3 and I am working on one of the examples in conditional independence documentation on the link http://pyphi.readthedocs.io/en/stable/examples/conditional_independence.html , I am getting an error which says 'module pyphi has no attribute 'tpm' . How can I resolve this issue?

import numpy as np
import pyphi
tpm = pyphi.examples.cond_depend_tpm()
print(tpm)
[[ 1. 0. 0. 0. ]
[ 0. 0.5 0.5 0. ]
[ 0. 0.5 0.5 0. ]
[ 0. 0. 0. 1. ]]
sbs_tpm = pyphi.convert.state_by_node2state_by_state(sbn_tpm)
print(sbs_tpm)
[[ 1. 0. 0. 0. ]
[ 0.25 0.25 0.25 0.25]
[ 0.25 0.25 0.25 0.25]
[ 0. 0. 0. 1. ]]
tpm2 = pyphi.examples.cond_independ_tpm()
print(tpm2)
[[ 0.5 0. 0. 0. 0.5 0. 0. 0. ]
[ 0. 0.5 0. 0. 0. 0.5 0. 0. ]
[ 0. 0. 0.5 0. 0. 0. 0.5 0. ]
[ 0. 0. 0. 0.5 0. 0. 0. 0.5]
[ 0.5 0. 0. 0. 0.5 0. 0. 0. ]
[ 0. 0. 0.5 0. 0. 0. 0.5 0. ]
[ 0. 0.5 0. 0. 0. 0.5 0. 0. ]
[ 0. 0. 0. 0.5 0. 0. 0. 0.5]]
sbn_tpm2 = pyphi.convert.state_by_state2state_by_node(tpm2)
print(sbn_tpm2)
[[[[ 0. 0. 0.5]
[ 0. 0. 0.5]]

[[ 0. 1. 0.5]
[ 1. 0. 0.5]]]

[[[ 1. 0. 0.5]
[ 0. 1. 0.5]]

[[ 1. 1. 0.5]
[ 1. 1. 0.5]]]]

AB = [0, 1]
C = [2]
tpm2_marginalizeC = pyphi.tpm.marginalize_out(C, sbn_tpm2)
Traceback (most recent call last):
File "<pyshell#16>", line 1, in
tpm2_marginalizeC = pyphi.tpm.marginalize_out(C, sbn_tpm2)
AttributeError: module 'pyphi' has no attribute 'tpm'

ValueError: math domain error

from graphiit import Graph
import pyphi
import sys
import numpy
numpy.set_printoptions(threshold=sys.maxsize)

pyphi.config.PARALLEL_CONCEPT_EVALUATION = True
pyphi.config.NUMBER_OF_CORES = -1
pyphi.config.MAXIMUM_CACHE_MEMORY_PERCENTAGE = 100

graph_config = [
('A','AND','B','C','D','E','F','G','H','I','J','K','L'),
('B','NAND','A','C','D','E','F','G','H','I','J','K','L'),
('C','OR','A','B','D','E','F','G','H','I','J','K','L'),
('D','COPY','A'),
('E','NOR','A','B','C','D','F','G','H','I','J','K','L'),
('F','NOT','A'),
('G','XOR','A','B','C','D','E','F','H','I','J','K','L'),
('H','XNOR','A','B','C','D','E','F','G','I','J','K','L'),
('I','MAJORITY','A','B','C','D','E','F','G','H','J','K','L'),
('J','MAJ','A','B','C','D','E','F','G','H','I','K','L'),
('K','MINORITY','A','B','C','D','E','F','G','H','I','J','L'),
('L','MIN','A','B','C','D','E','F','G','H','I','J','K')
]

graph = Graph(graph_config)

network = graph.pyphi_network()

state = (0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1)

subsystem = pyphi.Subsystem(network, state)

A, B, C, D, E, F, G, H, I, J, K, L = subsystem.node_indices

following the guidelines in https://pyphi.readthedocs.io/en/latest/examples/actual_causation.html:

X = Y = (A, B, C, D, E, F, G, H, I, J, K, L)

X_state = Y_state = (0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1)

transition = actual.Transition(network, X_state, Y_state, X, Y)

everything happens normally but when I do:

>>> transition.find_actual_cause((B, C))

or

account = actual.account(transition)
print(account) 

get error:


~/anaconda3/lib/python3.9/site-packages/pyphi/actual.py in find_actual_cause(self, mechanism, purviews)
    435     def find_actual_cause(self, mechanism, purviews=False):
    436         """Return the actual cause of a mechanism."""
--> 437         return self.find_causal_link(Direction.CAUSE, mechanism, purviews)
    438 
    439     def find_actual_effect(self, mechanism, purviews=False):

~/anaconda3/lib/python3.9/site-packages/pyphi/actual.py in find_causal_link(self, direction, mechanism, purviews, allow_neg)
    426         else:
    427             # This max should be most positive
--> 428             max_ria = max(self.find_mip(direction, mechanism, purview,
    429                                         allow_neg)
    430                           for purview in purviews)

~/anaconda3/lib/python3.9/site-packages/pyphi/actual.py in <genexpr>(.0)
    426         else:
    427             # This max should be most positive
--> 428             max_ria = max(self.find_mip(direction, mechanism, purview,
    429                                         allow_neg)
    430                           for purview in purviews)

~/anaconda3/lib/python3.9/site-packages/pyphi/actual.py in find_mip(self, direction, mechanism, purview, allow_neg)
    342             partitioned_probability = self.partitioned_probability(
    343                 direction, partition)
--> 344             alpha = log2(probability / partitioned_probability)
    345 
    346             # First check for 0

~/anaconda3/lib/python3.9/site-packages/pyphi/actual.py in log2(x)
     40 def log2(x):
     41     """Rounded version of ``log2``."""
---> 42     return round(_log2(x), config.PRECISION)
     43 
     44 

ValueError: math domain error

I know it's more likely that I'm doing something inappropriate, but I did not understand what ...

Also if:

transition.find_actual_cause((K, K))

then ...

CausalLink
  α = 0.413  [A, C, D] ◀━━ [K, K]

why? whether alpha smaller than 10 ** (- constant.epsilon), should return alpha = 0.0 and:

Filter out causal links with zero alpha

return DirectedAccount(filter(None, links))

1.2.0: failing test on s390x (Big endian): ERROR collecting test/test_subsystem_phi_max.py

Hello,

We're seeing a test failing on s390x while building pyphi for NeuroFedora:

CPU info:
Architecture:                    s390x
CPU op-mode(s):                  32-bit, 64-bit
Byte Order:                      Big Endian
CPU(s):                          3
On-line CPU(s) list:             0-2
Thread(s) per core:              1
Core(s) per socket:              1
Socket(s) per book:              1
Book(s) per drawer:              1
Drawer(s):                       3
NUMA node(s):                    1
Vendor ID:                       IBM/S390
Machine type:                    2964
CPU dynamic MHz:                 5000
CPU static MHz:                  5000
BogoMIPS:                        3033.00
Hypervisor:                      KVM/Linux
Hypervisor vendor:               KVM
Virtualization type:             full
Dispatching mode:                horizontal
L1d cache:                       384 KiB
L1i cache:                       288 KiB
L2d cache:                       6 MiB
L2i cache:                       6 MiB
L3 cache:                        64 MiB
L4 cache:                        480 MiB
NUMA node0 CPU(s):               0-2
Vulnerability Itlb multihit:     Not affected
Vulnerability L1tf:              Not affected
Vulnerability Mds:               Not affected
Vulnerability Meltdown:          Not affected
Vulnerability Spec store bypass: Not affected
Vulnerability Spectre v1:        Mitigation; __user pointer sanitization
Vulnerability Spectre v2:        Mitigation; execute trampolines
Vulnerability Srbds:             Not affected
Vulnerability Tsx async abort:   Not affected
Flags:                           esan3 zarch stfle msa ldisp eimm dfp edat etf3eh highgprs te vx sie

The build logs are below:

+ py.test-3.9
============================= test session starts ==============================
platform linux -- Python 3.9.0rc1, pytest-6.0.2, py-1.9.0, pluggy-0.13.1 -- /usr/bin/python3
cachedir: .pytest_cache
rootdir: /builddir/build/BUILD/pyphi-1.2.0, configfile: pytest.ini
plugins: lazy-fixture-0.6.3
collecting ... collected 482 items / 1 error / 481 selected
==================================== ERRORS ====================================
_______________ ERROR collecting test/test_subsystem_phi_max.py ________________
test/test_subsystem_phi_max.py:63: in <module>
    expected_mips = {
test/test_subsystem_phi_max.py:64: in <dictcomp>
    cut: {
test/test_subsystem_phi_max.py:65: in <dictcomp>
    direction: {
test/test_subsystem_phi_max.py:66: in <dictcomp>
    mechanism: subsystem[cut].find_mip(direction, mechanism, purview)
pyphi/subsystem.py:585: in find_mip
    phi, partitioned_repertoire = self�[39;49;00m.evaluate_partition(
pyphi/subsystem.py:535: in evaluate_partition
    phi = repertoire_distance(
pyphi/distance.py:281: in repertoire_distance
    dist = directional_emd(direction, r1, r2)
pyphi/distance.py:266: in directional_emd
    return�[39;49;00m round�[39;49;00m(func(d1, d2), config.PRECISION)
pyphi/distance.py:143: in hamming_emd
    return�[39;49;00m emd(d1, d2, _hamming_matrix(N))
pyemd/emd.pyx:49: in pyemd.emd.emd
    ?�[39;49;00m?�[39;49;00m?�[39;49;00m
E   ValueError: Little-endian buffer not supported on big-endian compiler
=========================== short test summary info ============================
ERROR test/test_subsystem_phi_max.py - ValueError: Little-endian buffer not s...
!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!
=============================== 1 error in 1.14s ===============================

The complete build logs are attached:

pyphi-1.2.0-buildlog.txt
pyphi-1.2.0-rootlog.txt

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.