Component

Component is an ensemble of plugins. In general, users can register Plugin`s to `Component, and tell it the varibales you wanna get. Component will auto-deduce the workflow based on the registered plugins’ depends_on and provides.

In addition, if some component is fixed, i.e. the distribution of variables is independent on the parameters, component will not do the deduction and simulation.

The base class is Component.

class appletree.Component(name: Optional[str] = None, llh_name: Optional[str] = None, **kwargs)[source]

Bases: object

Base class of component.

__init__(name: Optional[str] = None, llh_name: Optional[str] = None, **kwargs)[source]

Initialization.

Parameters
  • bins – bins to generate the histogram. * For irreg bins_type, bins must be bin edges of the two dimensions. * For meshgrid bins_type, bins are sent to jnp.histogramdd.

  • bins_type – binning scheme, can be either irreg or meshgrid.

_clip(result: list)[source]

Clip simulated result.

add_eps_to_hist: bool = True
compile()[source]

Hook for compiling simulation code.

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

Hook for workflow deduction.

force_no_eff: bool = False
get_normalization(hist, parameters, batch_size=None)[source]

Return the normalization factor of the histogram.

implement_binning(mc, eff)[source]

Apply binning to MC data.

Parameters
  • mc – data from simulation.

  • eff – efficiency of each event, as the weight when making a histogram.

property lineage
property lineage_hash
multiple_simulations(key, batch_size, parameters, times, apply_eff=False)[source]

Simulate many times and move results to CPU because the memory limit of GPU.

multiple_simulations_compile(key, batch_size, parameters, times, apply_eff=False)[source]

Simulate many times after new compilation and move results to CPU because the memory limit of GPU.

norm_type: str = ''
rate_name: str = ''
set_binning(**kwargs)[source]

Set binning of component.

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

Hook for simulation with histogram output.

For the component that needs simulation, we have a child class ComponentSim.

class appletree.ComponentSim(*args, **kwargs)[source]

Bases: Component

Component that needs MC simulations.

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

Initialization.

property code

Code of simulation function.

compile()[source]

Build simulation function and cache it to share._cached_functions.

deduce(data_names: Union[List[str], Tuple[str]] = ['cs1', 'cs2'], func_name: str = 'simulate', nodep_data_name: str = 'batch_size', force_no_eff: bool = False)[source]

Deduce workflow and code.

Parameters
  • data_names – data names that simulation will output.

  • func_name – name of the simulation function, used to cache it.

  • nodep_data_name – data_name without dependency will not be deduced.

  • force_no_eff – force to ignore the efficiency, used in yield prediction.

dependencies_deduce(data_names: Union[List[str], Tuple[str]] = ['cs1', 'cs2', 'eff'], dependencies: Optional[List[Dict]] = None, nodep_data_name: str = 'batch_size') list[source]

Deduce dependencies.

Parameters
  • data_names – data names that simulation will output.

  • dependencies – dependency tree.

  • nodep_data_name – data_name without dependency will not be deduced.

dependencies_simplify(dependencies)[source]

Simplify the dependencies.

flush_source_code(data_names: Union[List[str], Tuple[str]] = ['cs1', 'cs2', 'eff'], func_name: str = 'simulate', nodep_data_name: str = 'batch_size')[source]

Infer the simulation code from the dependency tree.

property lineage
new_component(llh_name: Optional[str] = None, pass_binning: bool = True)[source]

Generate new component with same binning, usually used on predicting yields.

register(plugin_class)[source]

Register a plugin to the component.

register_all(module)[source]

Register all plugins defined in module.

Can pass a list/tuple of modules to register all in each.

save_code(file_path)[source]

Save the code to file.

set_config(configs)[source]

Set new global configuration options.

Parameters

configs – dict, configuration file name or dictionary

show_config(data_names: Union[List[str], Tuple[str]] = ['cs1', 'cs2', 'eff'])[source]

Return configuration options that affect data_names.

Parameters

data_names – Data type name

simulate_hist(key, batch_size, parameters)[source]

Simulate and return histogram.

Parameters
  • key – key used for pseudorandom generator.

  • batch_size – number of events to be simulated.

  • parameters – a dictionary that contains all parameters needed in simulation.

simulate_weighted_data(key, batch_size, parameters)[source]

Simulate and return histogram.

For the component that is fixed, ComponentFixed should be used instead.

class appletree.ComponentFixed(*args, **kwargs)[source]

Bases: Component

Component whose shape is fixed.

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

Initialization.

deduce(data_names: Union[List[str], Tuple[str]] = ['cs1', 'cs2'])[source]

Deduce the needed parameters and make the fixed histogram.

property lineage
simulate()[source]

Fixed component does not need to simulate.

simulate_hist(parameters, *args, **kwargs)[source]

Return the fixed histogram.

simulate_weighted_data(parameters, *args, **kwargs)[source]

Simulate and return histogram.

There are some default plugins with registrations in appletree.components. Check them as a quick start on how to build your own component. See also