From 5349eb49182c99f85c9d6ad41761cce3879ff0b9 Mon Sep 17 00:00:00 2001 From: nawtrey Date: Sun, 18 Aug 2024 14:44:30 -0700 Subject: [PATCH] BENCH: Add cycle flux benchmark * Adds new benchmarks for the `calculations.calc_net_cycle_flux` function. Benchmark calculates the net cycle flux for all cycles in each diagram so it will scale not only with performance, but also with the number of cycles. --- benchmarks/benchmarks/bench_calculations.py | 58 +++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/benchmarks/benchmarks/bench_calculations.py b/benchmarks/benchmarks/bench_calculations.py index f8caac6..1628adc 100644 --- a/benchmarks/benchmarks/bench_calculations.py +++ b/benchmarks/benchmarks/bench_calculations.py @@ -4,6 +4,7 @@ import numpy as np import networkx as nx +import kda from kda import graph_utils, calculations, diagrams @@ -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, + )