Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BENCH: Add cycle flux benchmark #114

Merged
merged 1 commit into from
Aug 18, 2024
Merged
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
58 changes: 58 additions & 0 deletions benchmarks/benchmarks/bench_calculations.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import numpy as np
import networkx as nx

import kda
from kda import graph_utils, calculations, diagrams


Expand Down Expand Up @@ -150,3 +151,60 @@ def peakmem_calc_sigma(self, graph, output_strings):
key=self.key,
output_strings=output_strings,
)


class CycleFlux:
"""
A benchmark to test the time and space complexity of the
`calculations.calc_net_cycle_flux()` function.
"""
param_names = ["graph", "output_strings"]
params = [
[
"3-state",
"Hill-5-state",
"Hill-8-state",
],
[
True,
False,
]
]

def setup(self, graph, output_strings):
if output_strings:
key = "name"
else:
key = "val"
self.key = key
G = build_graph(graph=graph)
model = kda.KineticModel(G=G)
model.build_cycles()
self.G = model.G
self.cycles = model.cycles
self.dir_edges = diagrams.generate_directional_diagrams(
G=self.G, return_edges=True)

def time_calc_net_cycle_flux(self, graph, output_strings):
# benchmark cycle flux calculation algorithm
# for various models we commonly use for testing
for cycle in self.cycles:
calculations.calc_net_cycle_flux(
G=self.G,
cycle=cycle,
order=cycle[:2],
key=self.key,
output_strings=output_strings,
dir_edges=self.dir_edges,
)

def peakmem_calc_net_cycle_flux(self, graph, output_strings):
for cycle in self.cycles:
calculations.calc_net_cycle_flux(
G=self.G,
cycle=cycle,
order=cycle[:2],
key=self.key,
output_strings=output_strings,
dir_edges=self.dir_edges,
)
Loading