Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ _Next version_
### Fixes
- Fixed `convert.be2le_state_by_state()` and `convert.le2be_state_by_state()`;
previously the columns were not permuted
- Fixed `distribution.unflatten()`, which passed its arguments to
`repertoire_shape()` in the wrong order (`(purview, N)` instead of
`(range(N), purview)`) and raised `TypeError: argument of type 'int' is not
iterable` on every call.

1.2.0
-----
Expand Down
37 changes: 19 additions & 18 deletions benchmarks/benchmarks/compute.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
import copy
import timeit

Expand All @@ -9,28 +10,28 @@

class BenchmarkConstellation:

params = [["parallel", "sequential"], ["basic", "rule154", "fig16"]]
param_names = ["mode", "network"]
params = [['parallel', 'sequential'], ['basic', 'rule154', 'fig16']]
param_names = ['mode', 'network']
number = 1
repeat = 1

def setup(self, mode, network):
if network == "basic":
if network == 'basic':
self.subsys = examples.basic_subsystem()
elif network == "rule154":
elif network == 'rule154':
network = examples.rule154_network()
state = (1,) * 5
self.subsys = Subsystem(network, state, network.node_indices)
elif network == "fig16":
elif network == 'fig16':
network = examples.fig16()
state = (0,) * 7
self.subsys = Subsystem(network, state, network.node_indices)
else:
raise ValueError(network)

if mode == "parallel":
if mode == 'parallel':
config.PARALLEL_CONCEPT_EVALUATION = True
elif mode == "sequential":
elif mode == 'sequential':
config.PARALLEL_CONCEPT_EVALUATION = False
else:
raise ValueError(mode)
Expand All @@ -44,11 +45,11 @@ def time_constellation(self, mode, network):
class BenchmarkMainComplex:

params = [
["parallel", "sequential"],
["basic", "rule154", "fig16"],
["local", "redis"],
['parallel', 'sequential'],
['basic', 'rule154', 'fig16'],
['local', 'redis'],
]
param_names = ["mode", "network", "cache"]
param_names = ['mode', 'network', 'cache']

# Use `default_timer` (clock time) instead of process time because
# parallel execution spawns separate processes which are not counted
Expand All @@ -63,13 +64,13 @@ class BenchmarkMainComplex:

def setup(self, mode, network, cache):

if network == "basic":
if network == 'basic':
self.network = examples.basic_network()
self.state = (0, 1, 1)
elif network == "rule154":
elif network == 'rule154':
self.network = examples.rule154_network()
self.state = (0, 1, 0, 1, 1)
elif network == "fig16":
elif network == 'fig16':
self.network = examples.fig16()
self.state = (1, 0, 0, 1, 1, 1, 0)
else:
Expand All @@ -79,17 +80,17 @@ def setup(self, mode, network, cache):
self.default_config = copy.copy(config.__dict__)

# Execution mode
if mode == "parallel":
if mode == 'parallel':
config.PARALLEL_CUT_EVALUATION = True
elif mode == "sequential":
elif mode == 'sequential':
config.PARALLEL_CUT_EVALUATION = False
else:
raise ValueError(mode)

# Cache mode
if cache == "local":
if cache == 'local':
config.REDIS_CACHE = False
elif cache == "redis":
elif cache == 'redis':
config.REDIS_CACHE = True
if _cache.RedisConn().ping() is False:
# No server running
Expand Down
1 change: 1 addition & 0 deletions benchmarks/benchmarks/emd.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-

import os

Expand Down
1 change: 1 addition & 0 deletions benchmarks/benchmarks/subsystem.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
import copy

from pyphi import Subsystem, compute, config, examples
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/benchmarks/tpm.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

class SimulateTPM:
def setup(self):
test_data = Path(__file__).resolve().parent / "../../test/data"
self.tpm = np.load(test_data / "ising_tpm.npy")
test_data = Path(__file__).resolve().parent / '../../test/data'
self.tpm = np.load(test_data / 'ising_tpm.npy')

seed_sequence = np.random.SeedSequence(ENTROPY)
self.rng = np.random.default_rng(seed_sequence)
Expand Down
1 change: 1 addition & 0 deletions benchmarks/benchmarks/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
import numpy as np

from pyphi import utils
Expand Down
19 changes: 10 additions & 9 deletions benchmarks/time_emd.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
import random
import timeit
from collections import defaultdict
Expand Down Expand Up @@ -337,10 +338,10 @@ def statement():

def print_results(emd, time):
"""Report the results of timing an EMD computation"""
print("%s %.2fs" % (emd, time))
print('%s %.2fs' % (emd, time))


if __name__ == "__main__":
if __name__ == '__main__':

# Dict of repertoires organized by purview size
repertoires = defaultdict(list)
Expand All @@ -349,12 +350,12 @@ def report():
"""Time and print results"""

print()
print("The reported times are the minimum of %d repetitions" % REPEAT)
print("Each timing is %d executions" % NUMBER)
print('The reported times are the minimum of %d repetitions' % REPEAT)
print('Each timing is %d executions' % NUMBER)
print()
print(
"Set set n = 0 for the `utils.purview_size(d1) > n` check \n"
"in `cause_emd` to see accurate timings for all purview sizes.")
'Set set n = 0 for the `utils.purview_size(d1) > n` check \n'
'in `cause_emd` to see accurate timings for all purview sizes.')
print()

# There are at least `k` data points for each purview size
Expand All @@ -365,16 +366,16 @@ def report():
data = random.sample(repertoires[purview_size], k)
num_repertoires = len(repertoires[purview_size])

print("%s-node purviews (timing %d/%d repertoires)" % (
print('%s-node purviews (timing %d/%d repertoires)' % (
purview_size, k, num_repertoires))

num_independent = len([d for d in repertoires[purview_size]
if pyphi.utils.independent(d[0])])

print("%d%% independent" % (
print('%d%% independent' % (
num_independent / num_repertoires * 100))

print("----------------------------------------------")
print('----------------------------------------------')

t = time_emd('hamming', data)
print_results('hamming', t)
Expand Down
50 changes: 25 additions & 25 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,48 +12,48 @@
from pyphi.conf import config
from pyphi.deferred.ray import ray, NO_RAY

log = logging.getLogger("pyphi.test")
log = logging.getLogger('pyphi.test')

collect_ignore = ["setup.py", ".pythonrc.py"]
collect_ignore = ['setup.py', '.pythonrc.py']
# Also ignore everything that git ignores.
with open(Path(__file__).parent / ".gitignore", mode="rt") as f:
collect_ignore += list(filter(None, f.read().split("\n")))
with open(Path(__file__).parent / '.gitignore', mode='rt') as f:
collect_ignore += list(filter(None, f.read().split('\n')))


IIT_3_CONFIG = "pyphi_config_3.0.yml"
IIT_3_CONFIG = 'pyphi_config_3.0.yml'

# Run slow tests separately with command-line option, filter tests
# ================================================================


def pytest_addoption(parser):
parser.addoption(
"--filter", action="store", help="only run tests with the given mark"
'--filter', action='store', help='only run tests with the given mark'
)
parser.addoption("--outdated", action="store_true", help="run outdated tests")
parser.addoption("--slow", action="store_true", help="run slow tests")
parser.addoption("--veryslow", action="store_true", help="run very slow tests")
parser.addoption('--outdated', action='store_true', help='run outdated tests')
parser.addoption('--slow', action='store_true', help='run slow tests')
parser.addoption('--veryslow', action='store_true', help='run very slow tests')


def pytest_runtest_setup(item):
filt = item.config.getoption("--filter")
filt = item.config.getoption('--filter')
if filt:
if filt not in item.keywords:
pytest.skip("only running tests with the '{}' mark".format(filt))
else:
if "outdated" in item.keywords and not item.config.getoption("--outdated"):
pytest.skip("need --outdated option to run")
if "slow" in item.keywords and not item.config.getoption("--slow"):
pytest.skip("need --slow option to run")
if "veryslow" in item.keywords and not item.config.getoption("--veryslow"):
pytest.skip("need --veryslow option to run")
if 'outdated' in item.keywords and not item.config.getoption('--outdated'):
pytest.skip('need --outdated option to run')
if 'slow' in item.keywords and not item.config.getoption('--slow'):
pytest.skip('need --slow option to run')
if 'veryslow' in item.keywords and not item.config.getoption('--veryslow'):
pytest.skip('need --veryslow option to run')


# PyPhi configuration management
# ================================================================


@pytest.fixture(scope="function")
@pytest.fixture(scope='function')
def restore_config_afterwards():
"""Reset PyPhi configuration after a test.

Expand All @@ -63,7 +63,7 @@ def restore_config_afterwards():
yield


@pytest.fixture(scope="session", autouse=True)
@pytest.fixture(scope='session', autouse=True)
def disable_progress_bars():
"""Disable progress bars during tests.

Expand All @@ -74,10 +74,10 @@ def disable_progress_bars():
yield


@pytest.fixture(scope="function")
@pytest.fixture(scope='function')
def use_iit_3_config():
"""Use the IIT-3 configuration for all tests."""
with open(IIT_3_CONFIG, mode="rt") as f:
with open(IIT_3_CONFIG, mode='rt') as f:
iit3_config = yaml.load(f, Loader=yaml.SafeLoader)
with pyphi.config.override(**iit3_config):
yield
Expand All @@ -87,7 +87,7 @@ def use_iit_3_config():
# ================================================================


@pytest.fixture(scope="session", autouse=True)
@pytest.fixture(scope='session', autouse=True)
def protect_caches(request):
"""Temporarily backup, then restore, the user's Redis caches
before and after the testing session.
Expand All @@ -96,7 +96,7 @@ def protect_caches(request):
"""
# Initialize a test Redis connection
original_redis_conn = redis.conn
redis.conn = redis.init(config.REDIS_CONFIG["test_db"])
redis.conn = redis.init(config.REDIS_CONFIG['test_db'])
yield
# Restore the cache after the last test has run
redis.conn = original_redis_conn
Expand All @@ -109,21 +109,21 @@ def _flush_redis_cache():


# TODO: flush Redis cache
@pytest.fixture(scope="function", autouse=True)
@pytest.fixture(scope='function', autouse=True)
def flushcache(request):
"""Flush the currently enabled cache.

This is called before every test case.
"""
log.info("Flushing caches...")
log.info('Flushing caches...')
_flush_redis_cache()


# Ray
# ================================================================


@pytest.fixture(scope="module")
@pytest.fixture(scope='module')
def ray_context():
context = ray.init(num_cpus=3)
yield context
Expand Down
4 changes: 2 additions & 2 deletions docs/_themes/LICENSE
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Modifications:
Modifications:

Copyright (c) 2010 Kenneth Reitz.


Original Project:
Original Project:

Copyright (c) 2010 by Armin Ronacher.

Expand Down
1 change: 0 additions & 1 deletion docs/_themes/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,3 @@ The following themes exist:

**kr_small**
small one-page theme. Intended to be used by very small addon libraries.

Loading