<jupyter_start><jupyter_text>Caching<jupyter_code>import os
from pyps import Basis, Hamiltonian
from pyps.stark import _radial_integral as radial_calc
from pyps.stark import _ang_integral as ang_calc
from pyps.zeeman import _zeeman as zeeman_calc
import matplotlib.pyplot as plt
# construct matrix
H = Hamiltonian(Basis(n_values=range(30, 40), MJ_values=[0, 1, 2, 3]))<jupyter_output><empty_output><jupyter_text>In-memory cache`pypositronium` stores the 'e0', 'stark' and 'zeeman' sparse matrices as hidden attributes, '_e0_matrix', '_stark_z_matrix' and '_zeeman_matrix'. In addition, functools.lru_cache is used to minimize duplicated calculations when building the matrices.<jupyter_code>radial_calc.cache_info()
ang_calc.cache_info()
zeeman_calc.cache_info()
# this takes a while...
H.stark(Fz=1.0, numerov=True)
H.zeeman(Bz=1.0)
radial_calc.cache_info()
ang_calc.cache_info()
zeeman_calc.cache_info()<jupyter_output><empty_output><jupyter_text>Long-term cache`joblib.dumps()` can be used to store an instance of Hamiltonian (including cached sparse matrices).<jupyter_code>from joblib import dump, load
cache_file = "Rydberg.joblib"
dump(H, cache_file)
H = load(cache_file)
H.stark(Fz=1.0)
H.zeeman(Bz=1.0)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10797743755036261, 'fraction_numerical': 0.014504431909750202, 'mean_word_length': 7.9352517985611515, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '24491', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 468, 'n_tokens_neox': 455, 'n_words': 105, 'path': 'notebooks/Caching.ipynb', 'repo_name': 'ad3ller/positronium_FS', 'size': '1241'}