Plugin

Plugin is the smallest simulation unit in appletree. All plugins must inherit from the appletree.Plugin.

class appletree.Plugin(llh_name: Optional[str] = None)[source]

Bases: object

The smallest simulation unit.

__call__(*args, **kwargs)[source]

Calls self.simulate.

__init__(llh_name: Optional[str] = None)[source]

Initialization.

depends_on: List[str] = []
property lineage
property lineage_hash
parameters: Tuple = ()
provides: List[str] = []
sanity_check()[source]

Check the consistency between depends_on, provides and in(out)put of self.simulate

simulate(*args, **kwargs)[source]

The main simulation function.

Parameters
  • key – a jnp.array with length 2, used to generate random variables. See https://jax.readthedocs.io/en/latest/jax-101/05-random-numbers.html

  • parameters – a dictionary with key being parameters’ names. Plugin will get values of self.parameters from this dictionary.

  • args – other args following key and parameters must be in the order of self.depends_on.

Returns

key and output simulated variables, ordered by self.provides. key will be updated if it’s used inside self.simulate to generate random variables.

takes_config = immutabledict({})

There are many default plugins under appletree.plugins.

Here is an example how a plugin works:

import appletree as apt

# generate a key for pseudorandom generator
key = apt.randgen.get_key()

energy_sampler = apt.plugins.common.UniformEnergySpectra()
key, energy = energy_sampler(
    key,       # key is always the first argument
    {},        # this plugin does not need any parameter so we can send an empty dict
    int(1e6),  # this is the batch_size, the only element in self.depends_on
)

Note that whatever key or parameters will be used in Plugin.simulate or not, they must be the first and second arguments, and key is always the first in the returned tuple.