Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Radiation Sources #28

Open
allen-adastra opened this issue Mar 27, 2024 · 7 comments
Open

Radiation Sources #28

allen-adastra opened this issue Mar 27, 2024 · 7 comments
Labels
enhancement New feature or request

Comments

@allen-adastra
Copy link
Collaborator

Excited to get my hands on this!

I noticed radiation sources aren't modeled yet. It seems Brems + Synchrotron radiation should be pretty simple to add; perhaps just using the same formulas as implemented in cfspopcon

Thoughts on me opening a PR as a simple starter task?

@allen-adastra allen-adastra added the enhancement New feature or request label Mar 27, 2024
@jcitrin
Copy link
Collaborator

jcitrin commented Mar 28, 2024

Hi Allen! Indeed, Brems and Synchrotron radiation aren't in there yet, and they were short term goals. I'll add issues for the short-term roadmap for visibility. If you're interested it would be great if you open a PR with this. I'd also discuss with @araju around how to incorporate this in the config. We'd likely want the Stott formula to be one model option, keeping things open for other model options like the Wesson formula (which RAPTOR uses). The config about to be significantly refactored: @araju can provide further details.

@allen-adastra
Copy link
Collaborator Author

@araju would be good to hear more about the config refactor.

I've got a particular config system POPSIM side to build vectorized configs for (e.g. random walk generators, combinatorial cases, etc.); would be good to keep similarity where possible.

@allen-adastra
Copy link
Collaborator Author

One thing I've been wondering is what the motivation of using the DynamicConfigSlice pattern is over just doing a tree_map that resolves time-dependent quantities? Example:

def resolve_paths(tree: PyTree[typing.Union[ArrayLike, diffrax.AbstractPath]], t0: float, *args) -> PyTree[ArrayLike]:
    """Resolve any AbstractPath objects in a PyTree to their values at time t0.

    Args:
        tree (PyTree[Union[ArrayLike, AbstractPath]]): A PyTree of ArrayLike and AbstractPath objects.
        t0 (float): The time at which to evaluate the paths.

    Returns:
        PyTree[ArrayLike]: A PyTree of ArrayLike with all AbstractPath objects resolved to their values at time t0.
    """
    tree_resolved = jax.tree_map(
        lambda leaf: leaf.evaluate(t0, *args) if isinstance(leaf, diffrax.AbstractPath) else leaf,
        tree,
        is_leaf=lambda x: isinstance(x, diffrax.AbstractPath),
    )
    return tree_resolved

@araju
Copy link
Contributor

araju commented Apr 10, 2024

@araju would be good to hear more about the config refactor.

I've got a particular config system POPSIM side to build vectorized configs for (e.g. random walk generators, combinatorial cases, etc.); would be good to keep similarity where possible.

tl;dr - we want the entire sim run to be configurable via "primitives" without having to write actual python code or deal with too many imports, etc. Current thinking is to use Fiddle for this Sim object.

Motivation:
Right now, the simulation runs are configured via files like this where you have to define a get_sim() method which calls get_config() and get_geometry(). There are 2 issues with this:

  1. The Config defined in there is a bit unweildy. Its structure is a holdover from PINT which TORAX is heavily based on. We need to have some more clear separation between runtime parameters and "static" config parameters. Also, the source params are a bit all over the place which need organizing.
  2. We want to make things more user-friendly so that people don't need to, say, import a new stepper if they want to change from a linear solver to newton-raphson. For people less familiar with Python, we want to provide a Fiddle-based entrypoint where all they see is a json-like config where they can easily change things with primitives instead of instantiating actual objects.

This is a WIP, and actually Ian is helping on it now as well.

@araju
Copy link
Contributor

araju commented Apr 10, 2024

One thing I've been wondering is what the motivation of using the DynamicConfigSlice pattern is over just doing a tree_map that resolves time-dependent quantities? Example:

def resolve_paths(tree: PyTree[typing.Union[ArrayLike, diffrax.AbstractPath]], t0: float, *args) -> PyTree[ArrayLike]:
    """Resolve any AbstractPath objects in a PyTree to their values at time t0.

    Args:
        tree (PyTree[Union[ArrayLike, AbstractPath]]): A PyTree of ArrayLike and AbstractPath objects.
        t0 (float): The time at which to evaluate the paths.

    Returns:
        PyTree[ArrayLike]: A PyTree of ArrayLike with all AbstractPath objects resolved to their values at time t0.
    """
    tree_resolved = jax.tree_map(
        lambda leaf: leaf.evaluate(t0, *args) if isinstance(leaf, diffrax.AbstractPath) else leaf,
        tree,
        is_leaf=lambda x: isinstance(x, diffrax.AbstractPath),
    )
    return tree_resolved

Great question. Basically, the input Config has 2 types of parameters: params that may be time-varying but really can simply change without recompilation, and params that must trigger a recompilation when they change. And it would be nice if the user-facing Config object did not have to be completely JAX-friendly.

In an effort to make it super clear the difference between these 2 types, we created the static and dynamic config slices. It also helps jit things while explicitly calling out the static args.

Now, that being said, the actual resolution to a specific value can be done the way you showed above. That's a good point. But the existence of the dynamic and static configs are more to help separate things for jitting.

Does that make sense?

@allen-adastra
Copy link
Collaborator Author

One thing I've been wondering is what the motivation of using the DynamicConfigSlice pattern is over just doing a tree_map that resolves time-dependent quantities? Example:

def resolve_paths(tree: PyTree[typing.Union[ArrayLike, diffrax.AbstractPath]], t0: float, *args) -> PyTree[ArrayLike]:
    """Resolve any AbstractPath objects in a PyTree to their values at time t0.

    Args:
        tree (PyTree[Union[ArrayLike, AbstractPath]]): A PyTree of ArrayLike and AbstractPath objects.
        t0 (float): The time at which to evaluate the paths.

    Returns:
        PyTree[ArrayLike]: A PyTree of ArrayLike with all AbstractPath objects resolved to their values at time t0.
    """
    tree_resolved = jax.tree_map(
        lambda leaf: leaf.evaluate(t0, *args) if isinstance(leaf, diffrax.AbstractPath) else leaf,
        tree,
        is_leaf=lambda x: isinstance(x, diffrax.AbstractPath),
    )
    return tree_resolved

Great question. Basically, the input Config has 2 types of parameters: params that may be time-varying but really can simply change without recompilation, and params that must trigger a recompilation when they change. And it would be nice if the user-facing Config object did not have to be completely JAX-friendly.

In an effort to make it super clear the difference between these 2 types, we created the static and dynamic config slices. It also helps jit things while explicitly calling out the static args.

Now, that being said, the actual resolution to a specific value can be done the way you showed above. That's a good point. But the existence of the dynamic and static configs are more to help separate things for jitting.

Does that make sense?

Gotcha; cool thanks! Yeah I did something similar with having a class Config for static "compile-time" configuration and class Params for (possibly time-dependent) "run-time" configuration. Although I'm not super confident that the way I set things up avoids all the foot-guns I would like to. I got your email, would be good to exchange notes!

@jcitrin
Copy link
Collaborator

jcitrin commented Jun 27, 2024

Bremsstrahlung added in #176 . Will keep this issue open for cyclotron and line radiation source discussions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants