Skip to content

Commit

Permalink
Revert default value of parallel=False. Update docs. Bump version n…
Browse files Browse the repository at this point in the history
…umber
  • Loading branch information
MetinSa committed Oct 13, 2022
1 parent b3aafdb commit 3906bbe
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
38 changes: 22 additions & 16 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,31 +86,37 @@ bandpass is assumed if a sequence of frequencies are used without providing weig
![Bandpass integrated emission](img/bandpass_integrated.png)


## Gridding the interplanetary dust density distribution
In the following example we tabulate the density distribution of the DIRBE interplanetary dust model
and plot the cross section of the diffuse cloud components density in the yz-plane.

```python
{!examples/get_density_contour.py!}
```
![Interplanetary dust distribution](img/density_grid.png)


## Multiprocessing
By default, ZodiPy runs concurrently and will spawn processes based on the number of available CPU's
(given by `os.cpu_count()`). This can be turned off by initializing `Zodipy` with `parallel=False`.
The number of CPUs can be manually specified by using the `n_proc` keyword when initializing `ZodiPy`.

## Parallelization
If you are not using ZodiPy in an already parallelized environment **and** are working with large pointing sequences, setting `parallel=True` when initializing `Zodipy` will improve the performance. ZodiPy will then automatically distribute the pointing to all available CPU's, given by `multiprocessing.cpu_count()` or to `n_proc` if this argument is provided.

```python hl_lines="15 16"
{!examples/get_parallel_emission.py!}
```

!!! warning "Windows users"
On windows, the parallel code must be executed in a `if __name__ == "__main__"` guard to avoid spawning infinite processes:
Windows users must make sure to wrap the `get_*_emission_*` function calls in a `if __name__ == "__main__"` guard to avoid spawning infinite processes:
```python
...
if __name__ == "__main__":
emission = model.get_emission_pix(
...
)
```

!!! warning "Using ZodiPy in parallelized environments"
If ZodiPy is used in a parallelized environment one may have to specifically set the environment variable
`OMP_NUM_THREADS=1` to avoid oversubscription. This is due automatic parallelization in third party libraries such as `healpy` where for instance the `hp.Rotator` object automatically parallelizes rotation of unit vectors.
This means that when using ZodiPy with pointing in a coordinate system other than ecliptic, even if `Zodipy` is initialized with `parallel=False`, `healpy` will under the hood automatically distribute the pointing to available CPU's.


## Visualizing the interplanetary dust distribution of a model
It is possible to visualize the three-dimensional interplanetary dust distribution of the models used in
ZodiPy by using the `tabulate_density` function which takes in a interplanetary dust model and a custom grid.

In the following example we tabulate the density distribution of the DIRBE interplanetary dust model
and plot the cross section of the diffuse cloud components density in the yz-plane.

```python
{!examples/get_density_contour.py!}
```
![Interplanetary dust distribution](img/density_grid.png)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]
name = "zodipy"
homepage = "https://github.com/MetinSa/zodipy"
version = "0.7.1"
version = "0.7.2"
description = "Software for simulating zodiacal emission"
authors = ["Metin San <[email protected]>"]
readme = "README.md"
Expand Down
6 changes: 3 additions & 3 deletions zodipy/zodipy.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Zodipy:
valid model range. Default is `False`.
parallel (bool): If `True`, input pointing sequences will be split among all
available cores on the machine, and the emission will be computed in parallel.
This is useful for large simulations. Default is `True`.
This is useful for large pointing chunks. Default is `False`.
n_proc (int): Number of cores to use when parallel computation. Defaults is None,
which will use all available cores.
solar_cut (u.Quantity[u.deg]): Cutoff angle from the sun in degrees. The emission
Expand All @@ -83,7 +83,7 @@ def __init__(
self,
model: str = "dirbe",
extrapolate: bool = False,
parallel: bool = True,
parallel: bool = False,
n_proc: int | None = None,
solar_cut: u.Quantity[u.deg] | None = None,
solar_cut_fill_value: float = np.nan,
Expand Down Expand Up @@ -451,7 +451,7 @@ def _compute_emission(
delta=self.ipd_model.delta,
**asdict(interpolated_source_params),
)
# Distribute pointing to available CPUs and compute the emission in parallel.
# Distribute pointing to CPUs and compute the emission in parallel.
if self.parallel:
n_proc = multiprocessing.cpu_count() if self.n_proc is None else self.n_proc

Expand Down

0 comments on commit 3906bbe

Please sign in to comment.