Raytrax is an open source Python library for simulating electron cyclotron heating of fusion plamas. I started working on the code at Proxima Fusion and we jointly open sourced it this week. This blog post explains what the code is about.
Fusion energy#
Fusion energy recreates the sun’s power source on earth: by heating a plasma (ionized gas) to around 100 million degrees, pairs of nuclei are made to fuse into a heavier nucleus, releasing energy in the process. Building power plants based on this principle would unlock an enormous amount of energy without carbon emissions and without dependence on scarce fuels distributed unequally across the globe.
Since 100 million degrees is too hot for any material to handle, strong magnetic fields are used to keep a safe distance between the plasma and the walls of the fusion device.
Fusion heating#
In the sun, the heat needed to ignite fusion is generated by the sun’s own gravity that compresses and heats the gas at its core. On earth, we need to provide that heating externally. There are two established methods to achieve this: by particle beams or by electromagnetic waves.
Electron cyclotron resonance#
When hot plasma is confined into a donut-like (toroidal) shape by strong magnetic fields, the negatively charged electrons whizz around the donut at a very high speed, but on a corkscrew-like path, since the magnetic field twists their trajectory closely around its field lines. This spiralling motion has an associated oscillation frequency, which is called the electron cyclotron resonance frequency. For existing and projected fusion devices, this frequency is at the level of hundreds of Gigahertz, i.e. hundreds of billions of oscillations per second.
The idea of electron cyclotron resonance heating (ECRH) is to use focused microwave beams at precisely this oscillation frequency to transfer energy from outside the plasma (from a microwave generator called a [gyrotron](https://en.wikipedia.org/wiki/Gyrotron)) to the electrons in the plasma.
This principle has been validated and works reliably on many research fusion devices around the world, including Wendelstein 7-X in Greifswald, Germany. It will also be used at ITER, which is currently under construction in Cadarache, France.
Ray tracing#
In designing a scientific fusion device or a future power plant that employs ECRH as its heating method, finding the ideal location, direction, frequency, and power of the microwave beam is one of the challenges. Whether the beam can transfer its energy to the plasma or not depends sensitively on many parameters, including the magnetic field strength, plasma density, plasma temperature, and others. Simulating this beam and the energy transfer is exactly what Raytrax is about.
The physics of a microwave beam in a plasma has many similarities to a light ray shining through a glass of water: the ray is refracted, no longer taking a straight path. In the case of ECRH, the beam can be bent to a curve depending on the plasma density and temperature. Predicting this path by simulation can be achieved with the method of ray tracing.
Once the path of the beam is known, the next question is whether the energy is transferred to the plasma or not. If the plasma were akin to the glass of water, the beam would just shine through and not lose any energy – instead potentially damaging the opposing wall of the device. To achieve successful heating, the plasma must be “transparent” up to the point where the beam reaches the region where it resonantly excites the electrons and is [absorbed](https://en.wikipedia.org/wiki/Absorption_(electromagnetic_radiation), transferring all its energy to the plasma.
Raytrax in a nutshell#
Raytrax solves the equations for ray tracing and absorption for a given beam and plasma. Thus it can be used to simulate ECRH heating of a fusion device.
The relevant physics are known already since the 1980s and several software implementations have been created since. So Raytrax does not innovate the physics aspect. In a sense, it reflects a general trend as fusion energy moves closer to becoming a reality: the focus shifts from physics research to engineering; in this case, software engineering.
Concretely, there are two things that are new about Raytrax: it’s implemented in JAX and it’s released under a permissive open source license. Let me explain both points in more detail.
JAX#
JAX is an open source Python library for array computation that is developed by Google and was originally conceived for Machine Learning applications. While it is very popular for Machine Learning, it is also seeing increased adoption for scientific computing libraries like Raytrax because of two attractive properties:
- It automatically compiles source code in the background, making it much faster than if it were executed as ordinary Python; at the same time, the source code is still written in Python, a popular langugage that is easy to read and maintain.
- It allows for automatic differentation of functions.
Automatic differentiation means that the derivative, i.e. the change of a computation’s outputs with respect to changes in its inputs, can be computed with much less computational effort. This is crucial for optimization, i.e. when a computed quantity is to be maximized by finding the optimal input parameters. Optimization via automatic differentiation is not only what’s behind all the neural networks that power AI models revolutionizing the world around us, but it also drastically speeds up the search for ideal ECRH heating parameters when designing a new fusion device!
Open source#
Raytrax was first announced at the Open Source Software for Fusion Energy (OSSFE) Conference in Munich. This conference series brings together experts from academia, research labs and industry to foster collaboration on open source software that brings us closer to the shared goal of tapping into fusion as an energy source for humanity.
But sharing software openly is not simply an idealistic endeavor. Even for companies competing for external funding, who need to protect their core intellectual property, using and sharing software codes that implement physical phenomena has a huge benefit. It increases the reliability of the implementation and the trust in its correctness, by subjecting it to the scrutiny of an entire community.
I’m grateful that Proxima Fusion is supporting this open science idea by agreeing to open source the portion of the code that I developed in house, and by continuing to collaborate with me to add another asset to the fusion community’s toolbox.
Next steps#
Now that Raytrax is open source, the next step is to validate it against existing ECRH codes, which has only been done partially so far. Already before being fully validated, the scientific community as well as other interested players in the fusion domain are invited to try it out and give feedback. Contributions are welcome, for instance by interfacing Raytrax with other open source codes such as MHD equilibrium solvers for stellarators and tokamaks.