Skip to content
pedronaethePublic

About

Jipole is a Julia-based imaging tool built on the general relativistic ray-tracing framework of ipole. Using ForwardDiff.jl, it computes intensity derivatives with respect to input parameters, enabling fast and precise gradient-based fitting of synthetic images to observational data.

Topics

Resources

Stars

13 stars

Watchers

1 watching

Forks

Repository files navigation

GitHub last commit License: MIT GitHub repo stars

Jipole

A Julia-based radiative transfer code for curved spacetimes with automatic differentiation capabilities. More details available on the paper published in ApJ.

Overview

Jipole is an ipole-based Julia implementation designed to perform radiative transfer calculations in curved spacetimes, with a particular focus on black hole imaging. The code leverages Julia's automatic differentiation (autodiff) to compute derivatives of input parameters, enabling gradient based optimization methods. For this project, we used ForwardDiff.jl (Revels et al. 2016).

Current Development Status

The current version of Jipole is capable of producing images for Iharm3D and KHARMA file types.

The code is currently able to perform slow-light runs and has been compared with the well estabished code Blacklight (C. White. 2022) and ipole (Moscibrodzka & Gammie 2017).

We also have implemented the test problems described in Section 3.2 of Gold et al. 2020 and thin disk model as described in the Prather et al. 2023.

Installation and Setup

First-Time Setup

We advise you to run Jipole on Julia 1.12+

If this is your first time using Jipole, you'll need to set up the Julia environment and install the required dependencies:

  1. Navigate to the project directory:

    cd /path/to/jipole
  2. Start Julia with multithreading capabilities:

    julia --project="."
  3. Install Packages

    using Pkg
    Pkg.instantiate()

This command will install all the packages specified in the Project.toml and Manifest.toml files.

Running Jipole from Terminal

julia --project="." --threads=32 scripts/main.jl scripts/pars/example_par.toml
  • --project=scripts uses the scripts environment, which loads Jipole from this repository.
  • --threads sets the number of CPU threads used for raytracing.
  • The last argument is the parameter file.

Every run is set up by a TOML parameter file (see scripts/pars/example_par.toml). Anything left out falls back to a default, and unknown entries print a warning. The sections are:

Section What it sets
[physical] Black hole mass MBH in solar masses, mass unit m_unit ("MAD", "SANE" or a number in grams), slow_light switch
[dump] dump_filepath: a single dump or a directory of dumps (iharm3d .h5 or KHARMA .phdf); t_init/t_final select dumps by simulation time when it is a directory
[plasma] Electron temperature model (Rhigh, Rlow, beta_crit), polar cut th_beg, magnetization cuts sigma_cut, sigma_cut_high
[camera] Observer distance ro in units of M, inclination theta_o and azimuth phi (degrees)
[image] Resolution pixels_x/pixels_y, field of view fov_size (µas), offsets xoff/yoff
[observing] Frequency freq (Hz), source distance source_distance_pc
[raytracing] Step limit per geodesic maxnstep, and mode = "cpu" or "gpu"
[output] Output filename and format ("ipole" writes ipole-compatible HDF5); with several dumps, the dump index is appended (name_00945.h5)

Example GRMHD Dump

You can download an example dump file in dataverse.

Gradients ([gradient])

With on = true, Jipole also computes the derivative of every pixel's intensity with respect to each parameter listed in wrt, using forward-mode automatic differentiation (ForwardDiff.jl). They are written next to the image as grad/<parameter>.

Available parameters: MBH, M_unit, Rhigh, Rlow, beta_crit, th_beg, sigma_cut, sigma_cut_high, ro, th, phi, sourceD. Gradients currently require mode = "cpu" and slow_light = false.

Polarization ([polarization])

With on = true, Jipole also computes Stokes Q, U, V and the Faraday depth of every pixel, as ipole does without -unpol: the coherency tensor is parallel-transported along each geodesic and evolved with thermal synchrotron emission, absorption and Faraday rotation and conversion. The output file then holds them in pol (Stokes I, Q, U, V in CGS intensity, then the Faraday depth), next to the unpolarized image unpol; Q and U follow the IAU convention (EVPA East of North).

  • The section is optional; leaving it out is the same as on = false.
  • It works with mode = "cpu" and with [gradient], which then also writes the derivatives of pol as grad_pol/<parameter>. It does not work with slow light.
  • mode = "gpu" is implemented but has not been run on a GPU yet.

Flux fitting ([fit])

With flux_fit = true, Jipole first finds the m_unit for which the mean flux over the selected dumps equals flux_value (Jy), and then renders with it; m_unit is used as the starting guess.

  • The fit averages fit_amount evenly spaced dumps, rendered at a reduced resolution fitting_res, and stops when the mean flux is within fitting_tol of the target.
  • fit_save = true also keeps the fit images in <output folder>/fit/.

Slow light ([physical].slow_light, [slowlight])

By default, each dump is imaged on its own (fast light). With slow_light = true, Jipole accounts for the light travel time through the evolving flow:

  • Every pixel's geodesic is traced once.
  • Radiative transfer is then integrated through a sliding window of three consecutive dumps as simulation time advances.
  • This produces one frame every image_cadence (GM/c³).

dump_filepath must be a directory. engine = "cpu" or "gpu" selects where the transfer runs. Output goes to a slow_sims folder.

GPU

mode = "gpu" raytraces on an NVIDIA GPU through CUDA.jl, which is loaded only when requested. The first image includes a few seconds of kernel compilation, so the GPU pays off for large images or many dumps; for small images the multithreaded CPU is often faster.

Plotting

There is a plotting script provided in scripts/ folder. If the path is a directory, the script will plot all the output h5 files inside it, if it is just a single file, this one single file will be plotted.

The script can be executed from terminal following:

julia --project=. scripts/plot.jl path/to/folder

The script will be added to a folder called Figs within the path specified.

Jupyter Kernel Installation

To use Jipole with Jupyter notebooks, install the project-specific kernel:

using IJulia
IJulia.installkernel("Jipole", "--project=" * Base.current_project())

This creates a dedicated Jupyter kernel that automatically loads the Jipole project environment.

Package Structure

Jipole is a regular Julia package (src/Jipole.jl). Every file under src/ is its own capitalized submodule, reachable as Jipole.<ModuleName>, e.g. Jipole.Camera.camera_position, Jipole.Geodesics.get_pixel, Jipole.Radiation.integrate_emission!.

Three interchangeable emission models are provided as submodules — Jipole.Analytic, Jipole.ThinDisk, and Jipole.Iharm — each defining its own parameters type (AnalyticParams, ThinDiskParams, IharmParams). Which model runs is decided by which parameters object you construct and pass around, via Julia's multiple dispatch — there is no global model switch to edit.

using Jipole

# Analytic torus (Gold et al. 2020)
model = Jipole.Analytic.AnalyticParams(bhspin, Rout, cstartx, cstopx, rmax_geo, MBH)

# Thin disk
model = Jipole.ThinDisk.ThinDiskParams(bhspin, Rout, cstartx, cstopx, MBH, Mdot, Rstop)

# GRMHD simulation dump
model = Jipole.Iharm.read_header(dump_filepath, MBH)

From there, the same calls (Jipole.Camera.camera_position(...), Jipole.Geodesics.get_pixel(...), Jipole.Radiation.integrate_emission!(...)) work regardless of which model you constructed — see example_notebooks/GenerateImages.ipynb for the analytic/thin-disk models side by side, and example_notebooks/GenerateImageGRMHD.ipynb for the GRMHD model.

Running Jipole in a Jupyter Notebook

Starting the Environment

  1. Navigate to the project directory:

    cd /path/to/jipole
  2. Start Julia with multithreading capabilities:

    JULIA_NUM_THREADS=xx julia --project="."

    Replace xx with the number of CPU cores you want to utilize.

  3. Launch JupyterLab:

    using IJulia
    IJulia.jupyterlab(dir=pwd())

Using Jupyter Notebooks

  1. Open your web browser and navigate to the JupyterLab interface (typically http://localhost:8888)
  2. When creating or opening a notebook, ensure you select the Jipole kernel for this project from the kernel menu (install one with using IJulia; IJulia.installkernel("Jipole", "--project=" * abspath(".")) if you don't have one yet)
  3. Every notebook simply starts with using Jipole.

Notebooks Overview

  • ComputeGeodesics.ipynb
    Computes geodesics for each pixel and allows for debugging and visualization of the trajectories. Useful for inspecting geodesics before integrating intensity.

  • GenerateImage.ipynb
    Computes the final intensity map for thin-disk or analytical models, performing forward integration of emission along geodesics.

  • GenerateImageGRMHD.ipynb
    Computes the final intensity map for a GRMHD Iharm3D snapshot, performing forward integration of emission along geodesics.

  • Autodiff.ipynb
    Performs differentiable ray tracing to compute derivatives of the image intensity with respect to parameters like black hole spin (a) and observer inclination (θ). Uses the conjugate gradient algorithm to recover ground truth parameters from a computed intensity map, demonstrating gradient-based parameter estimation.

References

Contact

Pedro Naethe Motta at pedronaethemotta [at] usp [dot] br

About

Jipole is a Julia-based imaging tool built on the general relativistic ray-tracing framework of ipole. Using ForwardDiff.jl, it computes intensity derivatives with respect to input parameters, enabling fast and precise gradient-based fitting of synthetic images to observational data.

Topics

Resources

Stars

13 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages