Setup
The code allows one to specify a full lensing system, with observations, free parameters, and constants, using a configuration string or a configuration file in YAML format. A special set of functions is responsible for loading the specified configuration, generating the necessary code, and running it to perform model inference.
Example
As an example, consider the grid created from the following configuration file, which can be also obtained with this simple call:
julia> gravitymodel()parameters: # Put any global definition here. # Free parameters are defined using any distribution from Distributions # As shortcuts one can use ± for a univariate or bivariate Gaussian, # .. for a uniform distribution, ±ᵧ or ±ᵦ for gamma or beta distributions. # A few parameters have special meaning angular_unit: 1.0 # In arcseconds stable_lenses: auto # If true, lens planes will not change order lens_lenses: true # If true, lenses in multi-planes systems are lensed cosmology: # Put cosmological parameters in this optional section. As for standard # parameters, they can also be distributions, with shortcuts accepted. # The accepted cosmological parameters (with aliases) are # h₀ (or h_0), Nₑ (N_e), Ωₖ (Omega_k), Ωₘ (Omega_m), Ωᵣ (Omega_r), # Ωᵥ (Omega_v), Tᵧ (T_gamma), w₀ (w_0), wₐ (w_a). # By default, a flat standard cosmology is assumed. h₀: 0.69 Ωₘ: 0.29 lens-inversion: # This optional section is used to specify the parameters of the lens-inversion # algorithms. It is ignored for sampling.scheme = sourceplane. failsafe: always # Try to predict at least one image for each source grid: (-10:0.2:10, -10:0.2:10) # main grid specification (level 1) grid-refinement: critical-curves: 3 # grid refinement level for critical curves images: 2 # grid refinement level around observed images lenses: 3 # grid refinement level around lens centers sampling: # This compulsory section is used to specify the techniques used to sample # the free parameters. scheme: sourceplane # can be sourceplane, simplified-imageplane, imageplane, # extended-imageplane, or simulation likelihood-options: matches: all # match any predicted image with any observed one # use `best` to match the closest observed image duplicates: true # one predicted image can match multiple observed ones bayesianfactor: true # normalize in a Bayesian way the likelihood missedpredictionspenalty: true # penalize predicted & unobserved images algorithm: pt # can be maximum-a-posteriori, maximum-likelihood, emcee, # nested-sampler, mala, mhc, pt... algorithm-options: rounds: 10 #initialization: # lenses_main_NIE_b: 5.0 ± 0.1 warmup: 1 # number of steps to discard in the final chain iterations: 1000 # number of iterations to perform thinning: 1 # chain thinning timelimit: 10.0 # time limit for the map algoritm is seconds lenses: # This section must be used to specify the lens models to use. # It must be a list of lens types, each follwed by a dictionary of # fixed or free parameters. - NIE: # Non-singular isothermal ellipsoid name: main # optional lens name z: 0.5 # lens redshift x: (-0.382, -1.344) ± 0.003 # lens center σ: 150 .. 300 # velocity dispersion s: 0.001 # core radius q: 0.0 .. 0.9 # ellipticity (axis ratio) = b/a θ: 0 .. π # position angle north to east - Shear: # External shear lens name: shear z: 0.5 x: lenses_main_NIE_x # lens center fixed to the NIE value γ: (-0.5, -0.5) .. (0.5, 0.5) # shear vector sources: # This section must be used to specify the source types and the associated # images. - Point: z: 1.0 # source redshift x: (-10, -10) .. (10, 10) # source position images: # List of images produced by the source, with measurement errors - Point: x: (-1.328, -2.037) ± 0.003 - Point: x: (-1.478, -1.576) ± 0.003 - Point: x: (0.341, -1.960) ± 0.003 - Point: x: (0.0, 0.0) ± 0.003
Structure
A setup is structured dictionary containing all relevant information for a given gravitational lens system. The dictionary is divided in several sections, which together cover different aspects of the inference:
parameters: this section is used specify global parameters, which can be either constant or variable; it is also used for some specific configuration options.
cosmology: optional section to specify the cosmological model used. By default, a standard flat cosmology with $h = 0.69$ and $\Omega_\mathrm{m} = 0.29$ is used.
sampling: a section that defines the way the problem is solved, i.e.
the techniques used to infer the free parameters.lenses: a section containing the list of lenses that contribute to the given lens system. The code groups automatically lenses at the same redshift in a lens-plane.
sources: a section used to describe the kind of sources that are present, together with their associated images.
Unicode characters
Note how the setup makes use of unicode characters in many places: for example, the NIE lens above include a line with the σ character (indicating the lens velocity dispersion) and another one with the θ character (for the lens position angle). Similarly, the cosmology section includes cosmological parameters such as h₀ (the reduced Hubble constant) or Ωₘ (the dimensionless matter density). It is common practice to use symbols in Julia, and this is also adopted by Gravity.jl in its configuration file, as this improve the readability.
These characters can be entered in common editors by using suitable extensions which allow one to enter, say, σ by just typing \sigma. In particular, for Visual Studio Code one can install the "Unicode Math Input" extension, while for Atom there is a similar "latex completion" extension. As an alternative, one can always enter the unicode character in the Julia REPL and copy it in the configuration file.
Finally, it is anyway always possible to enter aliases of the parameters which avoid completely the use of unicode characters: for example, for σ one could just use sigma.