.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/benchmarks/rsa_density_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_density_scaling.py: RSA cost at different target fractions ======================================= Compare insertion times at fixed box size and radius. Each point is the median of three seeded independent runs; print achieved fractions and particle counts because stopping limits can prevent a target from being reached. Timings depend on the machine, build, and random seeds. RSA is irreversible. .. GENERATED FROM PYTHON SOURCE LINES 10-46 .. image-sg:: /gallery/benchmarks/images/sphx_glr_rsa_density_scaling_001.png :alt: RSA insertion cost :srcset: /gallery/benchmarks/images/sphx_glr_rsa_density_scaling_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none target 0.05, seed 11: achieved 0.0503, N=96, time=0.0002 s target 0.05, seed 22: achieved 0.0503, N=96, time=0.0002 s target 0.05, seed 33: achieved 0.0503, N=96, time=0.0002 s target 0.10, seed 11: achieved 0.1000, N=191, time=0.0004 s target 0.10, seed 22: achieved 0.1000, N=191, time=0.0004 s target 0.10, seed 33: achieved 0.1000, N=191, time=0.0004 s target 0.15, seed 11: achieved 0.1503, N=287, time=0.0009 s target 0.15, seed 22: achieved 0.1503, N=287, time=0.0009 s target 0.15, seed 33: achieved 0.1503, N=287, time=0.0009 s target 0.20, seed 11: achieved 0.2000, N=382, time=0.0018 s target 0.20, seed 22: achieved 0.2000, N=382, time=0.0019 s target 0.20, seed 33: achieved 0.2000, N=382, time=0.0018 s | .. code-block:: Python from time import perf_counter import matplotlib.pyplot as plt import numpy as np from PackLab import monte_carlo, samplers, ureg domain = monte_carlo.PackingDomain( 3 * ureg.micrometer, 3 * ureg.micrometer, 3 * ureg.micrometer, use_periodic_boundaries=True ) sampler = samplers.ConstantRadiusSampler(0.15 * ureg.micrometer) targets = [0.05, 0.10, 0.15, 0.20] timings = [] for target in targets: runs = [] for seed in (11, 22, 33): options = monte_carlo.RSAOptions() options.random_seed = seed options.maximum_attempts = 100000 options.maximum_consecutive_rejections = 20000 options.target_packing_fraction = target start = perf_counter() result = monte_carlo.RSASimulator(domain, sampler, options).run() runs.append(perf_counter() - start) print( f"target {target:.2f}, seed {seed}: " f"achieved {result.statistics.packing_fraction_geometry:.4f}, " f"N={result.statistics.sphere_count}, time={runs[-1]:.4f} s" ) timings.append(np.median(runs)) figure, axis = plt.subplots() axis.plot(targets, timings, "o-") axis.set( xlabel="target packing fraction", ylabel="median wall time (s)", title="RSA insertion cost" ) axis.grid(alpha=0.2) figure.tight_layout() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.074 seconds) .. _sphx_glr_download_gallery_benchmarks_rsa_density_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_density_scaling.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: rsa_density_scaling.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: rsa_density_scaling.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_