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: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ repos:
exclude: 'test_oauth.py'
- id: trailing-whitespace

- repo: https://github.com/ambv/black
rev: 19.3b0
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 25.12.0
hooks:
- id: black
name: black
Expand Down
1 change: 1 addition & 0 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 Down
10 changes: 7 additions & 3 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 All @@ -16,10 +17,11 @@

"""


def load_repertoire(name):
"""Load an array of repertoires in ./data/emd/."""
root = os.path.abspath(os.path.dirname(__file__))
filename = os.path.join(root, 'data', 'emd', name)
filename = os.path.join(root, "data", "emd", name)

return np.load(filename)

Expand All @@ -31,6 +33,7 @@ def generate_repertoire():

class BenchmarkEmdRandom:
"""Benchmark EMD on random repertoires."""

timeout = 100

def setup(self):
Expand All @@ -50,11 +53,12 @@ class BenchmarkEmdRule152:
The data is the first 100,000 repertoires encountered when computing
``big_phi`` for the network.
"""

timeout = 100

def setup(self):
self.d1 = load_repertoire('1.npy')
self.d2 = load_repertoire('2.npy')
self.d1 = load_repertoire("1.npy")
self.d2 = load_repertoire("2.npy")

def time_effect_emd(self):
for d1, d2 in zip(self.d1, self.d2):
Expand Down
9 changes: 5 additions & 4 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 Expand Up @@ -49,7 +50,7 @@ def clear_network_caches(network):
network.purview_cache = {}


class BenchmarkSubsystem():
class BenchmarkSubsystem:

def setup(self):
# 7-node network
Expand Down Expand Up @@ -104,7 +105,7 @@ def time_potential_purviews_with_cache(self):

class BenchmarkEmdApproximation:

params = ['emd', 'l1']
params = ["emd", "l1"]

number = 1
repeat = 1
Expand All @@ -116,9 +117,9 @@ def setup(self, distance):

self.default_config = copy.copy(config.__dict__)

if distance == 'emd':
if distance == "emd":
config.L1_DISTANCE_APPROXIMATION = False
elif distance == 'l1':
elif distance == "l1":
config.L1_DISTANCE_APPROXIMATION = True
else:
raise ValueError(distance)
Expand Down
25 changes: 14 additions & 11 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 All @@ -7,7 +8,8 @@
[1, 1, 0, 0, 0],
[0, 0, 0, 1, 0],
[0, 0, 1, 1, 1],
[1, 0, 0, 1, 1]]
[1, 0, 0, 1, 1],
]

cm1 = [
[0, 1, 1, 0, 1, 0, 0],
Expand All @@ -16,7 +18,8 @@
[0, 1, 0, 1, 1, 0, 0],
[0, 0, 0, 1, 1, 0, 0],
[0, 0, 0, 0, 0, 1, 1],
[0, 0, 0, 0, 0, 1, 1]]
[0, 0, 0, 0, 0, 1, 1],
]

cm2 = [
[1, 1, 0, 0, 0, 0, 0, 1],
Expand All @@ -26,15 +29,16 @@
[0, 0, 0, 1, 1, 1, 0, 0],
[0, 0, 0, 0, 1, 1, 1, 0],
[0, 0, 0, 0, 0, 1, 1, 1],
[1, 0, 0, 0, 0, 0, 1, 1]]
[1, 0, 0, 0, 0, 0, 1, 1],
]

cm3 = [[1] * 16] * 16


matrices = [cm0, cm1, cm2, cm3]


class BenchmarkBlockCm():
class BenchmarkBlockCm:

params = [0, 1, 2, 3]

Expand All @@ -45,19 +49,18 @@ def time_block_cm(self, m):
utils.block_cm(self.cm)


class BenchmarkReducibility():
class BenchmarkReducibility:

params = [[0, 1, 2, 3], ['block', 'full']]
param_names = ['cm', 'type']
params = [[0, 1, 2, 3], ["block", "full"]]
param_names = ["cm", "type"]

def setup(self, m, _type):
self.cm = np.array(matrices[m])

def time_reducibility(self, m, _type):
idxs = (tuple(range(self.cm.shape[0])),
tuple(range(self.cm.shape[1])))
idxs = (tuple(range(self.cm.shape[0])), tuple(range(self.cm.shape[1])))

if _type == 'block':
if _type == "block":
utils.block_reducible(self.cm, *idxs)
elif _type == 'full':
elif _type == "full":
utils.fully_connected(self.cm, *idxs)
Loading