.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/benchmarks/rsa_box_scaling.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_benchmarks_rsa_box_scaling.py: RSA generation scaling ====================== This benchmark measures the time to generate periodic random sequential adsorption (RSA) configurations as the box volume, and therefore the requested particle count, increases. The radius, target packing fraction, and stopping criteria remain fixed. The timings are specific to the machine and build configuration. They describe RSA insertion cost, not equilibrium sampling or agreement with an analytical hard-sphere model. .. GENERATED FROM PYTHON SOURCE LINES 14-23 .. code-block:: Python from time import perf_counter import matplotlib.pyplot as plt import numpy as np from PackLab import monte_carlo, samplers, ureg .. GENERATED FROM PYTHON SOURCE LINES 24-26 Define a fixed RSA workload --------------------------- .. GENERATED FROM PYTHON SOURCE LINES 26-33 .. code-block:: Python radius = 100 * ureg.nanometer target_packing_fraction = 0.08 box_lengths = np.linspace(3.0, 5.0, 10) * ureg.micrometer sampler = samplers.ConstantRadiusSampler(radius=radius) .. GENERATED FROM PYTHON SOURCE LINES 34-36 Time configuration generation at increasing box sizes ------------------------------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 36-63 .. code-block:: Python sphere_counts = [] elapsed_seconds = [] for index, box_length in enumerate(box_lengths): domain = monte_carlo.PackingDomain( box_length, box_length, box_length, use_periodic_boundaries=True, ) options = monte_carlo.RSAOptions() options.random_seed = 2026 + index options.maximum_attempts = 50_000 options.maximum_consecutive_rejections = 10_000 options.target_packing_fraction = target_packing_fraction started = perf_counter() result = monte_carlo.RSASimulator(domain, sampler, options).run() elapsed_seconds.append(perf_counter() - started) sphere_counts.append(result.statistics.sphere_count) print( f"{box_length.to('micrometer').magnitude:.1f} µm box: " f"{sphere_counts[-1]:4d} spheres in {elapsed_seconds[-1]:.3f} s" ) .. rst-class:: sphx-glr-script-out .. code-block:: none 3.0 µm box: 516 spheres in 0.001 s 3.2 µm box: 639 spheres in 0.001 s 3.4 µm box: 781 spheres in 0.002 s 3.7 µm box: 942 spheres in 0.002 s 3.9 µm box: 1124 spheres in 0.002 s 4.1 µm box: 1328 spheres in 0.003 s 4.3 µm box: 1555 spheres in 0.004 s 4.6 µm box: 1806 spheres in 0.004 s 4.8 µm box: 2083 spheres in 0.005 s 5.0 µm box: 2388 spheres in 0.007 s .. GENERATED FROM PYTHON SOURCE LINES 64-66 Display generation time against the realised workload ------------------------------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 66-76 .. code-block:: Python figure, axis = plt.subplots(figsize=(6, 4)) _ = axis.plot(sphere_counts, elapsed_seconds, "o-", color="#d97706") _ = axis.set( xlabel="accepted sphere count", ylabel="wall-clock time (s)", title="Periodic RSA generation scaling", ) axis.grid(alpha=0.25) figure.tight_layout() .. image-sg:: /gallery/benchmarks/images/sphx_glr_rsa_box_scaling_001.png :alt: Periodic RSA generation scaling :srcset: /gallery/benchmarks/images/sphx_glr_rsa_box_scaling_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.124 seconds) .. _sphx_glr_download_gallery_benchmarks_rsa_box_scaling.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: rsa_box_scaling.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: rsa_box_scaling.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: rsa_box_scaling.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_