.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/benchmarks/metropolis_sweep_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_metropolis_sweep_scaling.py: Metropolis sampling cost per sweep ================================== Measure the cost of advancing the same initial periodic configuration for several sweep counts. Each measurement starts a new sampler with the same seed; the reported median of three runs includes sampler construction. These short timings measure work, not equilibration or statistical accuracy. Report hardware, package version, and thread settings with results. .. GENERATED FROM PYTHON SOURCE LINES 11-47 .. image-sg:: /gallery/benchmarks/images/sphx_glr_metropolis_sweep_scaling_001.png :alt: Metropolis sampling cost :srcset: /gallery/benchmarks/images/sphx_glr_metropolis_sweep_scaling_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none 20 sweeps, 191 spheres: median 0.0169 s 50 sweeps, 191 spheres: median 0.0419 s 100 sweeps, 191 spheres: median 0.0835 s 200 sweeps, 191 spheres: median 0.1690 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 ) rsa = monte_carlo.RSAOptions() rsa.random_seed = 42 rsa.target_packing_fraction = 0.1 rsa.maximum_attempts = 100000 initial = monte_carlo.RSASimulator( domain, samplers.ConstantRadiusSampler(0.15 * ureg.micrometer), rsa ).run() counts = [20, 50, 100, 200] timings = [] for sweeps in counts: runs = [] for _ in range(3): options = monte_carlo.MetropolisOptions() options.random_seed = 43 options.number_of_sweeps = sweeps options.maximum_displacement = 0.05 * ureg.micrometer start = perf_counter() simulator = monte_carlo.MetropolisSimulator(domain, initial.sphere_configuration, options) simulator.run() runs.append(perf_counter() - start) timings.append(np.median(runs)) print(f"{sweeps} sweeps, {initial.statistics.sphere_count} spheres: median {timings[-1]:.4f} s") figure, axis = plt.subplots() axis.plot(counts, timings, "o-") axis.set(xlabel="sweeps", ylabel="median wall time (s)", title="Metropolis sampling cost") axis.grid(alpha=0.2) figure.tight_layout() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.999 seconds) .. _sphx_glr_download_gallery_benchmarks_metropolis_sweep_scaling.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: metropolis_sweep_scaling.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: metropolis_sweep_scaling.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: metropolis_sweep_scaling.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_