Time measurements for the different MTF solvers#
This routine measures the time taken for solving the problem presented in e1.laplace_transmission_mtf.ipynb with the routines mtf_laplace_n_spheres_point_source_direct_solver and mtf_laplace_n_spheres_point_source_indirect_solver.
Setup of the parameters and environment#
The following block is to control some environment variables. Specifically the threads allowed to use for some underlying libraries.
[1]:
import os
number = "1"
os.environ["OMP_NUM_THREADS"] = number
os.environ["OPENBLAS_NUM_THREADS"] = number
os.environ["MKL_NUM_THREADS"] = number
os.environ["VECLIB_MAXIMUM_THREADS"] = number
os.environ["NUMEXPR_NUM_THREADS"] = number
[2]:
import numpy as np
import biosspheres.miscella.spherearrangements as pos
import biosspheres.formulations.mtf.solvertemplates as solver
import biosspheres.formulations.mtf.solvertemplates as solver
import time
n = 8
big_l = 15
big_l_c = 55
r = 0.875
radii = np.ones(n) * r
d = 1.15
center_positions = pos.cube_vertex_positions(int(n**(1/3)), r, d)
sigma_e = 1.75
sigma_i = 0.75
sigmas = np.ones(n+1) * sigma_i
sigmas[0] = sigma_e
p0 = np.ones(3)*-5.
p0
tolerance = 10**(-10)
/opt/hostedtoolcache/Python/3.12.15/x64/lib/python3.12/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html
from .autonotebook import tqdm as notebook_tqdm
Time measurements#
We are going to measure (approximately) the time taken to solve a certain number of times using both methods
[3]:
number_of_times = 10
times_taken_direct = np.empty(number_of_times)
t0 = 0.
for i in np.arange(0, number_of_times):
print(i)
t0 = time.time()
traces = solver.mtf_laplace_n_spheres_point_source_direct_solver(n, big_l, big_l_c, radii, center_positions, sigmas, p0)
times_taken_direct[i] = time.time()-t0
times_taken_indirect = np.empty(number_of_times)
for i in np.arange(0, number_of_times):
print(i)
t0 = time.time()
traces = solver.mtf_laplace_n_spheres_point_source_indirect_solver(n, big_l, big_l_c, radii, center_positions, sigmas, p0, tolerance)
times_taken_indirect[i] = time.time()-t0
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
Results#
Averages:
[4]:
print("Direct method average: ", np.mean(times_taken_direct))
print("Indirect method average: ", np.mean(times_taken_indirect))
Direct method average: 10.637980508804322
Indirect method average: 1.0162214279174804
Standart deviations:
[5]:
print("Direct method std: ", np.std(times_taken_direct))
print("Indirect method sdt: ", np.std(times_taken_indirect))
Direct method std: 0.48223268985757184
Indirect method sdt: 0.020951528330944554
Minimum and maximum values:
[6]:
print("Direct method min: ", np.min(times_taken_direct))
print("Indirect method min: ", np.min(times_taken_indirect))
print("Direct method max: ", np.max(times_taken_direct))
print("Indirect method max: ", np.max(times_taken_indirect))
Direct method min: 9.575477838516235
Indirect method min: 0.9794068336486816
Direct method max: 11.478553533554077
Indirect method max: 1.0550894737243652
[ ]: