Skip to content

Commit

Permalink
Make global modes_cache object at startup. Bump version number.
Browse files Browse the repository at this point in the history
Also updated docs accordingly, and added startup code to ensure
common cases of jitted functions are compiled at load time.
  • Loading branch information
duetosymmetry committed Aug 20, 2019
1 parent 65d9b6c commit d607ecf
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 106 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,13 @@ qnm.download_data() # Only need to do this once
# Data directory /<something>/qnm/data contains 860 pickle files
```

Then, use `qnm.cached.KerrSeqCache` to load a
Then, use `qnm.modes_cache` to load a
`qnm.spinsequence.KerrSpinSeq` of interest. If the mode is not
available, it will try to compute it (see detailed documentation for
how to control that calculation).

```python
ksc = qnm.cached.KerrSeqCache(init_schw=True) # Only need init_schw once
mode_seq = ksc(s=-2,l=2,m=2,n=0)
grav_220 = qnm.modes_cache(s=-2,l=2,m=2,n=0)
omega, A, C = mode_seq(a=0.68)
print(omega)
# (0.5239751042900845-0.08151262363119974j)
Expand All @@ -107,7 +106,7 @@ s, l, m = (-2, 2, 2)
mode_list = [(s, l, m, n) for n in np.arange(0,7)]
modes = {}
for ind in mode_list:
modes[ind] = ksc(*ind)
modes[ind] = qnm.modes_cache(*ind)

plt.figure(figsize=(16,8))

Expand Down Expand Up @@ -142,7 +141,7 @@ s, l, n = (-2, 2, 0)
mode_list = [(s, l, m, n) for m in np.arange(-l,l+1)]
modes = {}
for ind in mode_list:
modes[ind] = ksc(*ind)
modes[ind] = qnm.modes_cache(*ind)

plt.figure(figsize=(16,8))

Expand Down
Binary file modified notebooks/example_22n.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified notebooks/example_2m0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
114 changes: 29 additions & 85 deletions notebooks/examples.ipynb

Large diffs are not rendered by default.

26 changes: 22 additions & 4 deletions qnm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@
>>> import qnm
>>> # qnm.download_data() # Only need to do this once
>>> ksc = qnm.cached.KerrSeqCache(init_schw=True) # Only need init_schw once per session
>>> mode_seq = ksc(s=-2,l=2,m=2,n=0)
>>> omega, A, C = mode_seq(a=0.68)
>>> grav_220 = qnm.modes_cache(s=-2,l=2,m=2,n=0)
>>> omega, A, C = grav_220(a=0.68)
>>> print(omega)
(0.5239751042900845-0.08151262363119974j)
(0.5239751042900845-0.08151262363119986j)
"""

Expand Down Expand Up @@ -55,3 +54,22 @@

from . import cached
from .cached import download_data

############################################################
## Package initialization

# Singleton for cache
modes_cache = cached.KerrSeqCache(init_schw=True)

# Ensure common versions of jitted functions are compiled
def _ensure_jitted():
finder = nearby.NearbyRootFinder(a=0.3, s=-2, m=2, A_closest_to=3.6+0.1j,
l_max=20, omega_guess=0.4-0.09j,
tol=1e-10, n_inv=0, Nr_max=4000)
finder.do_solve()
finder.set_params(Nr_max=float("inf"))
finder.do_solve()

return

_ensure_jitted()
2 changes: 1 addition & 1 deletion qnm/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.2.7"
__version__ = "0.3.0"
12 changes: 6 additions & 6 deletions qnm/cached.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
""" Caching interface to Kerr QNMs
This is a high-level interface to the package. An instance of
:class:`KerrSeqCache` will return instances of
This is a high-level interface to the package.
The global cache `qnm.modes_cache` (an instance of
:class:`KerrSeqCache`) will return instances of
:class:`qnm.spinsequence.KerrSpinSeq` from memory or disk. If a spin
sequence is neither in memory nor on disk then it will be computed and
returned.
Expand Down Expand Up @@ -193,11 +194,10 @@ class KerrSeqCache(object):
>>> import qnm
>>> # qnm.download_data() # Only need to do this once
>>> ksc = qnm.cached.KerrSeqCache(init_schw=True) # Only need init_schw once per session
>>> mode_seq = ksc(s=-2,l=2,m=2,n=0)
>>> omega, A, C = mode_seq(a=0.68)
>>> grav_220 = qnm.modes_cache(s=-2,l=2,m=2,n=0)
>>> omega, A, C = grav_220(a=0.68)
>>> print(omega)
(0.5239751042900845-0.08151262363119974j)
(0.5239751042900845-0.08151262363119986j)
"""

Expand Down
2 changes: 1 addition & 1 deletion qnm/nearby.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class NearbyRootFinder(object):
a: float [default: 0.]
Dimensionless spin of black hole, 0 <= a < 1.
s: int [default: 2]
s: int [default: -2]
Spin of field of interest
m: int [default: 2]
Expand Down
4 changes: 2 additions & 2 deletions qnm/radial.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def leaver_cf_inv_lentz_old(omega, a, s, m, A, n_inv,
>>> from qnm.radial import leaver_cf_inv_lentz_old, leaver_cf_inv_lentz
>>> print(leaver_cf_inv_lentz_old(omega=.4 - 0.2j, a=0.02, s=-2, m=2, A=4.+0.j, n_inv=0))
((-3.5662773770495546-1.5388710793384461j), 9.702542314939062e-11, 76)
((-3.5662773770495972-1.538871079338485j), 9.702532283649582e-11, 76)
Compare the two versions of the function:
Expand Down Expand Up @@ -317,7 +317,7 @@ def leaver_cf_inv_lentz(omega, a, s, m, A, n_inv,
>>> from qnm.radial import leaver_cf_inv_lentz
>>> print(leaver_cf_inv_lentz(omega=.4 - 0.2j, a=0.02, s=-2, m=2, A=4.+0.j, n_inv=0))
((-3.5662773770495546-1.5388710793384461j), 9.702542314939062e-11, 76)
((-3.5662773770495972-1.538871079338485j), 9.702532283649582e-11, 76)
References
----------
Expand Down
4 changes: 2 additions & 2 deletions qnm/schwarzschild/overtonesequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ class SchwOvertoneSeq(object):
>>> seq = SchwOvertoneSeq(s=-1, l=3, n_max=5)
>>> seq.find_sequence()
>>> print(seq.omega[5])
(0.5039017454081958-1.1703558890487786j)
(0.503901745408196-1.1703558890487784j)
Later, you want to go out to n=8:
>>> seq.extend(n_max=8)
>>> print(seq.omega[8])
(0.4227909293895908-1.9136575597714864j)
(0.422790929389591-1.9136575597714867j)
"""

Expand Down

0 comments on commit d607ecf

Please sign in to comment.