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:
objectThe smallest simulation unit.
- property lineage
- property lineage_hash
- sanity_check()[source]
Check the consistency between
depends_on,providesand in(out)put ofself.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
keyandparametersmust be in the order of self.depends_on.
- Returns
keyand output simulated variables, ordered by self.provides.keywill 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.