{ "cells": [ { "cell_type": "markdown", "id": "5ee7ff02-7b28-4141-aec9-8d848cd2645c", "metadata": {}, "source": [ "# Time measurements for the different MTF solvers" ] }, { "cell_type": "markdown", "id": "26d1333d-f72b-4d1e-8c0b-d8eb425cf164", "metadata": {}, "source": [ "This routine measures the time taken for solving the problem presented in [e1.laplace_transmission_mtf.ipynb](./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`." ] }, { "cell_type": "markdown", "id": "d6da62af-814e-477a-ae58-a6034df47ee5", "metadata": {}, "source": [ "## Setup of the parameters and environment" ] }, { "cell_type": "markdown", "id": "bd9fe33b-3d5b-47c0-b321-734d12a00569", "metadata": {}, "source": [ "The following block is to control some environment variables. Specifically the threads allowed to use for some underlying libraries." ] }, { "cell_type": "code", "execution_count": 1, "id": "cd821fb7-5603-4ef7-9105-b44a213a5d00", "metadata": {}, "outputs": [], "source": [ "import os\n", "number = \"1\"\n", "os.environ[\"OMP_NUM_THREADS\"] = number\n", "os.environ[\"OPENBLAS_NUM_THREADS\"] = number\n", "os.environ[\"MKL_NUM_THREADS\"] = number\n", "os.environ[\"VECLIB_MAXIMUM_THREADS\"] = number\n", "os.environ[\"NUMEXPR_NUM_THREADS\"] = number" ] }, { "cell_type": "code", "execution_count": 2, "id": "b2a9744d-af6f-4cc1-8f0d-60215f789726", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import biosspheres.miscella.spherearrangements as pos\n", "import biosspheres.formulations.mtf.solvertemplates as solver\n", "import biosspheres.formulations.mtf.solvertemplates as solver\n", "import time\n", "\n", "n = 8\n", "big_l = 15\n", "big_l_c = 55\n", "\n", "r = 0.875\n", "radii = np.ones(n) * r\n", "\n", "d = 1.15\n", "center_positions = pos.cube_vertex_positions(int(n**(1/3)), r, d)\n", "\n", "sigma_e = 1.75\n", "sigma_i = 0.75\n", "sigmas = np.ones(n+1) * sigma_i\n", "sigmas[0] = sigma_e\n", "\n", "p0 = np.ones(3)*-5.\n", "p0\n", "\n", "tolerance = 10**(-10)\n" ] }, { "cell_type": "markdown", "id": "4a123537-4b49-453c-8e52-ee9a12b6342d", "metadata": {}, "source": [ "## Time measurements" ] }, { "cell_type": "markdown", "id": "40d41770-06f6-4887-b30a-2061c5d2f0a1", "metadata": {}, "source": [ "We are going to measure (approximately) the time taken to solve a certain number of times using both methods" ] }, { "cell_type": "code", "execution_count": 3, "id": "08b5b3b6-4d68-486b-a637-d61925425f92", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0\n", "1\n", "2\n", "3\n", "4\n", "5\n", "6\n", "7\n", "8\n", "9\n", "0\n", "1\n", "2\n", "3\n", "4\n", "5\n", "6\n", "7\n", "8\n", "9\n" ] } ], "source": [ "number_of_times = 10\n", "times_taken_direct = np.empty(number_of_times)\n", "t0 = 0.\n", "for i in np.arange(0, number_of_times):\n", " print(i)\n", " t0 = time.time()\n", " traces = solver.mtf_laplace_n_spheres_point_source_direct_solver(n, big_l, big_l_c, radii, center_positions, sigmas, p0)\n", " times_taken_direct[i] = time.time()-t0\n", "\n", "times_taken_indirect = np.empty(number_of_times)\n", "for i in np.arange(0, number_of_times):\n", " print(i)\n", " t0 = time.time()\n", " traces = solver.mtf_laplace_n_spheres_point_source_indirect_solver(n, big_l, big_l_c, radii, center_positions, sigmas, p0, tolerance)\n", " times_taken_indirect[i] = time.time()-t0" ] }, { "cell_type": "markdown", "id": "28c38177-848a-4f6f-8cdf-c7d56026b97b", "metadata": {}, "source": [ "## Results" ] }, { "cell_type": "markdown", "id": "6fe6249f-9c7c-44de-b4f8-4857e573935b", "metadata": {}, "source": [ "Averages:" ] }, { "cell_type": "code", "execution_count": 4, "id": "565359d5-ce3b-4dac-a1b6-ce12338eda87", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Direct method average: 9.47792592048645\n", "Indirect method average: 2.7520662546157837\n" ] } ], "source": [ "print(\"Direct method average: \", np.mean(times_taken_direct))\n", "print(\"Indirect method average: \", np.mean(times_taken_indirect))" ] }, { "cell_type": "markdown", "id": "9981a3f6-39a6-4842-9043-536be6046091", "metadata": {}, "source": [ "Standart deviations:" ] }, { "cell_type": "code", "execution_count": 5, "id": "41ce8cbd-d550-4add-8386-4212589e9bbe", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Direct method std: 0.16462314321045604\n", "Indirect method sdt: 0.05972414899239749\n" ] } ], "source": [ "print(\"Direct method std: \", np.std(times_taken_direct))\n", "print(\"Indirect method sdt: \", np.std(times_taken_indirect))" ] }, { "cell_type": "markdown", "id": "a238ba39-c058-4559-b518-24790b79413f", "metadata": {}, "source": [ "Minimum and maximum values:" ] }, { "cell_type": "code", "execution_count": 6, "id": "dcaa1d02-2eb5-4fbf-b67a-7ea5baeebc3b", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Direct method min: 9.244473934173584\n", "Indirect method min: 2.6842405796051025\n", "Direct method max: 9.244473934173584\n", "Indirect method max: 2.6842405796051025\n" ] } ], "source": [ "print(\"Direct method min: \", np.min(times_taken_direct))\n", "print(\"Indirect method min: \", np.min(times_taken_indirect))\n", "print(\"Direct method max: \", np.max(times_taken_direct))\n", "print(\"Indirect method max: \", np.max(times_taken_indirect))" ] }, { "cell_type": "code", "execution_count": null, "id": "ff48fb9d-23b8-40ab-b13c-ce4f50c3c32e", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "reqbiosspheresnotebooks", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.18" } }, "nbformat": 4, "nbformat_minor": 5 }