.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/_501_simulating_networks.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples__501_simulating_networks.py: Simulating a Network in Parallel ================================ While the ultimate objective is to process multiple fractionated samples together (with sample as a dim), this pattern may be useful in the mean-time. It demonstrates how to process multiple samples in parallel, with a progressbar to provide feedback. The function my_simulator and the class TqdmParallel is defined in simulating_networks_tools.py, and are imported here to demonstrate. .. GENERATED FROM PYTHON SOURCE LINES 13-23 .. code-block:: default import pandas as pd import plotly from joblib import delayed from elphick.mass_composition import MassComposition from elphick.mass_composition.datasets.sample_data import sample_data from elphick.mass_composition.flowsheet import Flowsheet from elphick.mass_composition.utils.parallel import TqdmParallel from examples._simulating_network_functions import my_simulator .. GENERATED FROM PYTHON SOURCE LINES 24-26 Execute multiple simulations ---------------------------- .. GENERATED FROM PYTHON SOURCE LINES 26-37 .. code-block:: default df_data: pd.DataFrame = sample_data() obj_mc: MassComposition = MassComposition(df_data, name='sample') d_inputs: dict[int, MassComposition] = {1: obj_mc, 2: obj_mc.add(obj_mc), 3: obj_mc.add(obj_mc).add(obj_mc)} results: list[tuple[int, Flowsheet]] = TqdmParallel(n_jobs=3, prefer="processes", total=len(d_inputs))( delayed(my_simulator)(item) for item in d_inputs.items() ) d_results = {sid: fs for sid, fs in results} .. rst-class:: sphx-glr-script-out .. code-block:: none 0%| | 0/3 [00:00, 2: , 3: } .. GENERATED FROM PYTHON SOURCE LINES 42-44 View the network for a sample ----------------------------- .. GENERATED FROM PYTHON SOURCE LINES 44-47 .. code-block:: default fig = d_results[1].table_plot() plotly.io.show(fig) .. raw:: html :file: images/sphx_glr__501_simulating_networks_001.html .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 8.025 seconds) .. _sphx_glr_download_auto_examples__501_simulating_networks.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: _501_simulating_networks.py <_501_simulating_networks.py>` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: _501_simulating_networks.ipynb <_501_simulating_networks.ipynb>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_