# \[ANN\] AstroNbodySim.jl: Unitful and differentiable gravitational N-body simulation code in Julia

**URL:** <https://discourse.julialang.org/t/ann-astronbodysim-jl-unitful-and-differentiable-gravitational-n-body-simulation-code-in-julia/74782>\
**Category:** Package Announcements\
**Tags:** package\
**Created:** [January 18, 2022, 6:10am UTC](https://discourse.julialang.org/t/ann-astronbodysim-jl-unitful-and-differentiable-gravitational-n-body-simulation-code-in-julia/74782 "2022-01-18T06:10:50Z")\
**Posts on this page:** 11\
**Page:** 2

<div class="post-metadata">

**Author:** ![islent](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/islent/32/11326_2.png) [@islent](https://discourse.julialang.org/u/islent)\
**Post date:** [January 19, 2022, 3:13am UTC](https://discourse.julialang.org/t/ann-astronbodysim-jl-unitful-and-differentiable-gravitational-n-body-simulation-code-in-julia/74782/21 "2022-01-19T03:13:05Z")

</div>

> If some of these assumptions don’t hold, you get basically garbage numbers out

Thanks for the information.

[https://discourse.julialang.org/t/re-ann-astronbodysim-jl-unitful-and-differentiable-gravitational-n-body-simulation-code-in-julia/74817/2?u=islent](https://discourse.julialang.org/t/re-ann-astronbodysim-jl-unitful-and-differentiable-gravitational-n-body-simulation-code-in-julia/74817/2)

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [January 19, 2022, 6:06am UTC](https://discourse.julialang.org/t/ann-astronbodysim-jl-unitful-and-differentiable-gravitational-n-body-simulation-code-in-julia/74782/22 "2022-01-19T06:06:51Z")

</div>

> [@carstenbauer](#):
>
> While I agree, improving generic array abstractions seems like a very different and potentially much harder development effort to me.
> 
> Also, what are suggesting specifically? Should one use `DArray` s in combination with DiffEq for distributed ODE solving? If I just read the [DiffEq docs](https://diffeq.sciml.ai/dev/basics/faq/#GPUs,-multithreading-and-distributed-computation-support), I would think that I shouldn’t go down this route.

These days it’s PartitionedArrays that’s probably the best. But yes

> [@carstenbauer](#):
>
> So, I guess I should develop my own custom array type then? Is this mentioned / explained somewhere in the docs? I think an example showcasing something like this would be great. (Maybe I’m just not aware of it?)

if you’re writing a parallel code, then you’re going to be writing parallel array primitives, in which case you might as well stick that parallel array anywhere. Good parallel array types will be more useful than the applications that they are written for, so this would might have a Ewald summation package associated with it as well, but then it could be used with symplectic time steppers, implicit ones, etc. Locking such an object towards one application would be not the greatest use of dev resources, especially given that such array types are lacking yet the rest of what’s in there is rather straightforward.

Though the thing that really should get fixed here though is that the code is GPL.

---

<div class="post-metadata">

**Author:** ![longqian95](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/longqian95/32/6947_2.png) [@longqian95](https://discourse.julialang.org/u/longqian95)\
**Post date:** [January 19, 2022, 3:11pm UTC](https://discourse.julialang.org/t/ann-astronbodysim-jl-unitful-and-differentiable-gravitational-n-body-simulation-code-in-julia/74782/23 "2022-01-19T15:11:12Z")

</div>

We can combine `Measurements.jl` with `DifferentialEquations.jl` to solve an ODE with error propagation as [this tutorials](https://tutorials.sciml.ai/html/type_handling/02-uncertainties.html). This is one of advantages of Julia language, as mentioned in [The Unreasonable Effectiveness of Multiple Dispatch | Stefan Karpinski](https://www.youtube.com/watch?v=kc9HwsxE1OY). Combining with `Measurements.jl` with `AstroNbodySim.jl` has no big differences especially for small systems since they are essentially some ODEs. So this feature may be useful for some applications such as orbital dynamics and mission trajectory design, etc.

---

<div class="post-metadata">

**Author:** ![xbdong](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xbdong/32/32938_2.png) [@xbdong](https://discourse.julialang.org/u/xbdong)\
**Post date:** [January 20, 2022, 7:33am UTC](https://discourse.julialang.org/t/ann-astronbodysim-jl-unitful-and-differentiable-gravitational-n-body-simulation-code-in-julia/74782/24 "2022-01-20T07:33:08Z")

</div>

Two comments:

1. AstroNbodySim.jl as a (“small-system”) nbody simulator, there is Miller’s instability generically.  
See p.343 of Binney & Tremaine 2008 book.
2. So, as far as this measurements.jl feature is concerned, we think about applications that can be modeled with N\<3 . Then, what is that? 😄

> [@longqian95](#):
>
> We can combine `Measurements.jl` with `DifferentialEquations.jl` to solve an ODE with error propagation … has no big differences especially for small systems since they are essentially some ODEs.  
> So this feature may be useful for some applications such as orbital dynamics and mission trajectory design, etc.

---

<div class="post-metadata">

**Author:** ![xzackli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xzackli/32/38301_2.png) [@xzackli](https://discourse.julialang.org/u/xzackli)\
**Post date:** [January 20, 2022, 8:14am UTC](https://discourse.julialang.org/t/ann-astronbodysim-jl-unitful-and-differentiable-gravitational-n-body-simulation-code-in-julia/74782/25 "2022-01-20T08:14:19Z")

</div>

There _are_ situations where the error propagation and derivatives could be sensible, even for large N (i.e. [FlowPM](https://arxiv.org/abs/2010.11847)). There’s some link above to a discussion by Chris about how AD diverges on chaotic problems. We need to avoid chaos, so we need to zoom out to distance scales much larger than a typical orbit, and simulate time scales much shorter than the typical Lyapunov time. This can be the case for cosmological simulations in the weakly nonlinear regime.

I see that cosmological sims are on the roadmap! I look forward to trying those out. Have you seen [PencilFFTs](https://jipolanco.github.io/PencilFFTs.jl/dev/)?

---

<div class="post-metadata">

**Author:** ![islent](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/islent/32/11326_2.png) [@islent](https://discourse.julialang.org/u/islent)\
**Post date:** [January 20, 2022, 2:28pm UTC](https://discourse.julialang.org/t/ann-astronbodysim-jl-unitful-and-differentiable-gravitational-n-body-simulation-code-in-julia/74782/26 "2022-01-20T14:28:06Z")

</div>

> [@xzackli](#):
>
> I see that cosmological sims are on the roadmap! I look forward to trying those out. Have you seen [PencilFFTs](https://jipolanco.github.io/PencilFFTs.jl/dev/)?

Yes, I have. However, `PencilFFTs` is based on MPI, witch is incompatible with the parallelization scheme of `AstroNbodySim`. We plan to implement cosmological simulations by tree method and AMR Poisson solver.

---

<div class="post-metadata">

**Author:** ![murrayE](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/murraye/32/24428_2.png) [@murrayE](https://discourse.julialang.org/u/murrayE)\
**Post date:** [January 21, 2022, 9:09pm UTC](https://discourse.julialang.org/t/ann-astronbodysim-jl-unitful-and-differentiable-gravitational-n-body-simulation-code-in-julia/74782/27 "2022-01-21T21:09:48Z")

</div>

Do the simulations run on an non-nVidia, non-CUDA environment, e.g., an iMac?

---

<div class="post-metadata">

**Author:** ![islent](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/islent/32/11326_2.png) [@islent](https://discourse.julialang.org/u/islent)\
**Post date:** [January 22, 2022, 2:30am UTC](https://discourse.julialang.org/t/ann-astronbodysim-jl-unitful-and-differentiable-gravitational-n-body-simulation-code-in-julia/74782/28 "2022-01-22T02:30:59Z")

</div>

If you are asking whether the GPU module can run on non-NVIDIA environments, the answer is NO. Our GPU implementation is based on `CUDA.jl`.

If you are asking whether the other functionalities of `AstroNbodySim` can work on non-GPU platforms, the answer is YES. However, direct summation method and particle-mesh method on GPU will not be supported.

---

<div class="post-metadata">

**Author:** ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Post date:** [July 18, 2022, 4:59am UTC](https://discourse.julialang.org/t/ann-astronbodysim-jl-unitful-and-differentiable-gravitational-n-body-simulation-code-in-julia/74782/29 "2022-07-18T04:59:25Z")

</div>

I use Nvidia GT216 GLM (Quadro FX880M) it is not a GPU to play heavy core game like Assassin’s Creed. Can I run the GPU simulation with my condition? DO I still need Cuda installed for that?

I’ll try it today and tell you the result.

P.S. I want to create Julia package that can do Physics simulation like yours. Amazing you are !

---

<div class="post-metadata">

**Author:** ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Post date:** [July 19, 2022, 12:48am UTC](https://discourse.julialang.org/t/ann-astronbodysim-jl-unitful-and-differentiable-gravitational-n-body-simulation-code-in-julia/74782/30 "2022-07-19T00:48:22Z")

</div>

I try to test example 4 and add the dependencies but got an error:

 ![Capture d’écran_2022-07-18_20-38-21](https://global.discourse-cdn.com/julialang/original/3X/5/2/526b3273bf435cadabdec9a3c505da7e693e68a1.png)

---

<div class="post-metadata">

**Author:** ![islent](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/islent/32/11326_2.png) [@islent](https://discourse.julialang.org/u/islent)\
**Post date:** [July 19, 2022, 4:22am UTC](https://discourse.julialang.org/t/ann-astronbodysim-jl-unitful-and-differentiable-gravitational-n-body-simulation-code-in-julia/74782/31 "2022-07-19T04:22:41Z")

</div>

Can you capture the screenshot of full output?

It does not seem like problem stemming from AstroIC, because we set loose restrictions on dependencies.

Possible solutions are:

- update Reexport (and other packages)
- install packages depending on Reexport after installing AstroIC

PS: Please post usage problems on github issues

[Previous page](https://discourse.julialang.org/t/ann-astronbodysim-jl-unitful-and-differentiable-gravitational-n-body-simulation-code-in-julia/74782.md?page=1)
