bsmart package
Subpackages
- bsmart.collider package
- bsmart.data package
- bsmart.ml package
- bsmart.scans package
get_available_scans()- Scans
- bsmart.scans.AffineMC
- bsmart.scans.AL
- bsmart.scans.CMAES
- bsmart.scans.CMAES_ND
- bsmart.scans.Contour2D
- bsmart.scans.ContourGP
- bsmart.scans.DEAP
- bsmart.scans.Diver
- bsmart.scans.DLScanner
- bsmart.scans.Grid
- bsmart.scans.MCMC
- bsmart.scans.MLS
- bsmart.scans.MultiNest
- bsmart.scans.Random
- bsmart.scans.read_csv
- bsmart.scans.read_dir
- bsmart.scans.read_dir_mpi
- bsmart.scans.MLScanner
- bsmart.scans.Vegas
- bsmart.scripts package
- Submodules
- bsmart.scripts.bsmart_emcee module
- bsmart.scripts.bsmart_run module
- bsmart.scripts.build_examples module
- bsmart.scripts.install_heptools module
add_SARAH_paths()extract_tar()get_file()go_COLLIER()go_Diver()go_FlexibleSUSY()go_HiggsBounds()go_HiggsSignals()go_HiggsTools()go_LoopTools()go_MicrOMEGAs()go_MultiNest()go_SARAH()go_SModelS()go_SPheno()go_VevaciousPlusPlus()go_ZPEED()install_COLLIER()install_Diver()install_FlexibleSUSY()install_HiggsBoundsSignals()install_LoopTools()install_MicrOMEGAs()install_MultiNest()install_SARAH()install_SModelS()install_SPheno()install_Vevaciouspp()install_ZPEED()main()shell_command()use_requests()
- bsmart.scripts.prepare_bsmart module
- bsmart.scripts.prepare_model module
- bsmart.scripts.quick_start module
- Module contents
- bsmart.tools
- bsmart.tools.FlexibleSUSY
- bsmart.tools.HackAnalysis_LO
- bsmart.tools.HiggsBounds
- bsmart.tools.HiggsSignals
- bsmart.tools.HiggsTools
- bsmart.tools.MadAnalysisAllPAD
- bsmart.tools.MadAnalysisExpert
- bsmart.tools.MadGraph
- bsmart.tools.MadGraphHackAnalysis
- bsmart.tools.MicrOmegas
- bsmart.tools.SModelS
- bsmart.tools.SModelS2
- bsmart.tools.SPheno
- bsmart.tools.VacStab
- bsmart.tools.VevaciousPlusPlus
- bsmart.tools.ZPEED
- bsmart.tools.Zprime
- bsmart.tools.anyBSM
- bsmart.tools.flavio
- bsmart.tools.pass_tool
- bsmart.tools.resummino
- bsmart.tools.toy_targets
Submodules
bsmart.BSMArtBlackBox module
bsmart.BSMlikelihood module
Basic functions related to likelihoods, given here for convenience for scans that want them
- bsmart.BSMlikelihood.C_interval(val, lower, upper)[source]
Non-log version corresponding to LogC_interval.
- bsmart.BSMlikelihood.Clog_interval(val, lower, upper)[source]
Like C_interval, but with log-scaled values. WARNING: val, lower, upper must be strictly positive numbers.
- bsmart.BSMlikelihood.LogC_function(val, m, s)[source]
m is mean, s is variance, so lower = m-s, upper = m+s
Gives a value between -1 * max log and 0; looks very much like a LL
- bsmart.BSMlikelihood.LogC_interval(val, lower, upper)[source]
Log C-function based on an interval [lower, upper] where:
If both bounds finite: closed interval [lower, upper]
If only lower is given: [lower, +inf[
If only upper is given: ]-inf, upper]
If neither is given: always inside (zero penalty)
Returns 0.0 inside the allowed region and a negative log10(1 + distance) penalty outside.
- bsmart.BSMlikelihood.LogClog_function(val, m, s)[source]
Like LogC_function, but with log-scaled values. WARNING: val, m - s must be strictly positive numbers.
- bsmart.BSMlikelihood.LogClog_interval(val, lower, upper)[source]
Like LogC_interval, but with log-scaled values. WARNING: val, lower, upper must be strictly positive numbers.
- bsmart.BSMlikelihood.MakeGlobalLikelihood(observables_dict: dict, user_loglike: bool = False, return_type: str = None, max_loss: float = None, smooth_losses: bool = True)[source]
Makes a function that takes a list of observables and outputs a global likelihood Also returns a ‘mask’ list corresponding to whether a given observable is ignored or not; useful for machine-learning tasks.
This seems to work ok. I wonder whether it would be safer to wrap it into a class that stores the functions?
user_loglike is a legacy feature. If True it will use log likelihoods; if False it will use regular likelihoods.
The idea will be that the user tells the code what to provide to give a likelihood. So if what is provided is a log likelihood, they should provide EXPUSER; if it is an NLL it should be MINUSEXPUSER. This may then be undone by the requirements of the scan.
- return_type should be:
“Likelihood” (A likelihood), by default “LL” (Log Likelihood) “NLL” (Negative Log Likelihood)
smooth_losses is True by default. If true, then the function will always return a number (it should not raise an error if some observables are infinite or NaN), and in the case of log likelihoods the value is capped at max_loss.
max_loss is optional and only relevant for LL and NLL methods and when smooth_losses is True. It will cap the loss at this value (if provided), smoothing using a sigmoid. Otherwise a maximum value corresponding to 710.782712893384 ( = math.log(1+sys.float_info.max) + 1 on a standard system ) is used.
- bsmart.BSMlikelihood.MakeLikelihoodFunc(scaling, mean, var, lower_bound=None, upper_bound=None, log_scaling=False)[source]
- bsmart.BSMlikelihood.MakeLikelihoodFuncLog(scaling, mean, var, lower_bound=None, upper_bound=None, log_scaling=False)[source]
bsmart.BSMplots module
Routines to automatically generate simple plots using matplotlib
Function make_plots takes the scan as argument
In the settings the plots to be produced should just be pairs of variables and observables, or the ‘result’. But the result is not actually stored in the point in the RunManager … only in the csv/spectrum file etc.
We could have three strategies: 1) Take the points directly from the store in the runner in the_scan.RunManager.all_points or the_scan.RunManager.valid_points (not necessarily always there for every scan) 2) Read from csv file using pandas (easiest) 3) Read from the output_file which stores all spectrum files if the appropriate option is set
For other things (e.g. using only the selected points in an MCMC scan) this is scan dependent and we can’t be sure how or where the results are stored.
It would be useful to write a script that generates the
bsmart.BSMutil module
Some simple utilities that can be used either in the scans or in external programs
So far this includes routines for scaling up and down variables. To invoke them, use
Import BSMutil
in your scan.
Then
- bsmart.BSMutil.downscaler_capped(vmin, vmax)[source]
Uniform prior on the interval [0,1] but raises an error if outside
- bsmart.BSMutil.downscaler_func(vmin, vmax)[source]
Inverse of uniform prior, maps [vmin,vmax] -> [0,1]
- bsmart.BSMutil.downscaler_open(vmin, vmax)[source]
Rescale a range onto [0,1] but allow values outside
- bsmart.BSMutil.downscaler_symlinear(vmin, vmax)[source]
Inverse of Map [0.5,1] -> [|vmin|,|vmax|] and [0,0.5] -> [-|vmax|,-|vmin|] This should be a disjoint interval.
- bsmart.BSMutil.downscaler_symlog(vmin, vmax)[source]
Inverse of Map [0.5,1] -> vmin *exp (x*log(vmax/vmin)) and [0,0.5] -> - vmin *exp (x*log(vmax/vmin)) This should be a disjoint interval. _box = log(y/vmin)/log(vmax/vmin) _box = 2x -1 x = (_box + 1)/2
- bsmart.BSMutil.upscaler_capped(vmin, vmax)[source]
Uniform prior on the interval [0,1] but raises an error if outside
- bsmart.BSMutil.upscaler_expprior(vmin, vmax, psigma)[source]
P(y) ~ e^y. Coincides with MultiNest version when vmin = -infty, vmax=0, psigma > 0 or vmin=infty, vmax=0, psigma < 0
- bsmart.BSMutil.upscaler_open(vmin, vmax)[source]
Rescale a range onto [0,1] but allow values outside
bsmart.HEPRun module
HEPRun class for handling running and IO with HEP tools.
Part of BSMArt, but it is self-contained (nb requires zslha and the classes for the different tools) and you can import it into your own programs
In that case the useful classes are:
HEPRun (which manages everything) CoreRunner (which manages running on one core) DataPoint
You can use HEPRun to run batches of points (using multiprocessing!) or CoreRunner.run_point(point) to run individual points
This is useful for MPI running mode, where the multiprocessing is handled outside the program.
- Allowed settings in the input dictionary (“Setup” block unless otherwise specified):
RunName: Name of the run.
Cores: Number of cores to use.
TempDir: Temporary working directory.
debug: Enable debug mode (boolean).
SLHA_Output: Boolean, control SLHA output generation.
Skip SLHA Files: Boolean, for pure python scans (skips I/O).
Output File: Name for collected outputs.
Spectrum File: Name for intermediate spectrum file.
StoreInputs: Boolean, whether to store input Les Houches files.
StoreAllPoints: Boolean, whether to store all points (default True).
Store Output Files: Boolean, alias for StoreAllPoints.
Short: Boolean, enable tabbed output.
csv: Boolean, enable CSV output.
csv name: Name for the CSV file.
Precision: Integer, precision for observables.
Store Invalid: Boolean, store invalid points.
Store In Memory: Boolean, store DataPoint objects in memory.
StoreSeparateFiles: Boolean, store separate spectrum files.
StoreEverything: Boolean, retain all inputs and outputs for each point.
Use TQDM: Boolean, use tqdm progress bar.
- Other blocks:
Codes: Dictionary of codes to run.
Observables: Dictionary of observables.
Variables: Dictionary of variables.
Derived Variables: Dictionary of derived variables.
Fitting: Dictionary for fitting inputs.
MPI: Dictionary containing MPI settings (Size, Rank).
- class bsmart.HEPRun.CoreRunner(ParentRunner, name)[source]
Bases:
objectClass to handle running on one core, takes HEPRun as parent, which becomes the self.RunHandler
- class bsmart.HEPRun.DataPoint(ID: int, inputs: list = None)[source]
Bases:
objectClass to hold info about each point. We need at least an ID.
A list of inputs is the first step to filling. observables are a list of floats outputs are a list of results from the computation, intended to be returned to the scan. E.g. a likelihood valid is whether the point passes validity checks etc
- class bsmart.HEPRun.HEPRun(runsettings: RunSettings = None, write_inputfile: Callable = None, postprocess: Callable = None, log: Logger = None, inputs: dict | OrderedDict = {})[source]
Bases:
objectThis is the main class to handle running.
- class bsmart.HEPRun.HepTool(name, settings, global_settings=None)[source]
Bases:
objectTemplate class to run the different HEP tools Codes are supposed to place their output in spc_file which will get read at the end
At init we may also provide global settings so that the code can take what they need (e.g. number of cores) These should not be stored by default
But they may want access at intermediate stages to things like the input variables or details of the spectrum. For that we can use the DataPoint class
- class bsmart.HEPRun.RunSettings(inputs: str | dict | OrderedDict = None)[source]
Bases:
objectContainer class to store settings to be passed to the running module Ordinarily these are filled in in core.py
- bsmart.HEPRun.UpdateProgress(number, length, message='', finish=False)[source]
Ridiculously basic progress bar Implemented here so that we don’t need to install extra packages
If tqdm is installed, you can use it in this function. See the example below: from tqdm import tqdm
- with tqdm(total=length) as pbar:
- for i in range(number):
# Do stuff… pbar.update()
bsmart.core module
BSMArt Core module to define the basic Scan class
All scans inherit the basic features here.
- Useful settings:
‘StoreEverything’: will store all output from all codes in separate directories in All_Outputs ‘StoreAllPoints’: Keep all points. Default is to concatenate them into one file stored in Results ‘StoreSeparateFiles’: Separate the resulting spectrum files, stored in Results ‘Store In Memory’: Store all the points in memory during running; useful for plotting and for user-defined scans (defualt False) ‘Output File’: name for output file collecting spectra/csv/tabbed output ‘Spectrum File’: name for the spectrum file. Only really used internally ‘Merge Results’ : Merge the spectrum/csv files if MPI operation is used, also for MCMC Results. ‘csv’ : Store results in a csv file
- class bsmart.core.Scan(inputs, log)[source]
Bases:
objectParent Scan class from which all child NewScan classes are born
- configure_input_spc()[source]
We store a template input spectrum file and use zslha to write our input files for different codes by default. However, the user can overload write_lh_file or setlhvals as necessary if a different format is needed
- initialise()[source]
method to allow the user scan to overload run settings etc during the initialisation process
- lhsetSUSY(m0, m12, T0)[source]
Sets common SUSY soft scalar masses, gaugino masses and stop trilinear
- postprocess(Point, observables, data_point, temp_dir, log, lock=None)[source]
Default postprocessing method for use with SLHA output, you should overload this for more interesting/sophisticated scans
- postprocess_no_slha(Point, observables, data_point, temp_dir, log, lock=None)[source]
Default postprocessing method for use without SLHA output, you should overload this for more interesting/sophisticated scans
By default I will take this to be the
- varnames
## now setup the run manager self.runsettings=RunSettings(inputs[‘Setup’][‘RunName’]) self.runsettings.cores=inputs[‘Setup’][‘Cores’] self.runsettings.work_dir=inputs[‘Setup’][‘TempDir’] self.runsettings.debug=eval(inputs[‘Setup’][‘debug’]) self.runsettings.packagepath=inputs[‘Setup’][‘PackagePath’]
self.runsettings.no_slha_output=False
self.resume = eval(inputs[‘Setup’].get(‘Resume’,”False”))
- if inputs[‘MPI’][‘Size’] > 1:
self.runsettings.use_MPI=True
- if ‘SLHA_Output’ in inputs[‘Setup’]:
self.runsettings.no_slha_output=not eval(str(inputs[‘Setup’][‘SLHA_Output’]))
- if ‘Codes’ not in inputs:
self.log.error(‘No codes found in input file’) raise SystemExit
- else:
self.runsettings.codes=inputs[‘Codes’]
### add observables defined within the code to the global observables list if present for code in inputs[‘Codes’]:
- if eval(inputs[‘Codes’][code][‘Run’]) and ‘Observables’ in inputs[‘Codes’][code]:
- for obs in inputs[‘Codes’][code][‘Observables’]:
inputs[‘Observables’][obs] = inputs[‘Codes’][code][‘Observables’][obs]
- if ‘StoreInputs’ in inputs[‘Setup’]:
self.runsettings.store_inputs=eval(str(inputs[‘Setup’][‘StoreInputs’]))
- else:
self.runsettings.store_inputs=False
- if ‘Short’ in inputs[‘Setup’]:
self.runsettings.tabbed_output = eval(str(inputs[‘Setup’][‘Short’]))
- if ‘csv’ in inputs[‘Setup’]:
self.runsettings.csv_output = eval(str(inputs[‘Setup’][‘csv’]))
- if ‘csv name’ in inputs[‘Setup’]:
self.runsettings.csv_name=str(inputs[‘Setup’][‘csv name’])
- if ‘Precision’ in inputs[‘Setup’]:
self.runsettings.precision = int(inputs[‘Setup’][‘Precision’])
- if ‘StoreAllPoints’ in self.inputs[‘Setup’]:
self.runsettings.store_outputs=eval(self.inputs[‘Setup’][‘StoreAllPoints’])
- else:
self.runsettings.store_outputs=True
- if ‘Store In Memory’ in self.inputs[‘Setup’]:
self.runsettings.store_points=eval(self.inputs[‘Setup’][‘Store In Memory’])
- if ‘StoreSeparateFiles’ in self.inputs[‘Setup’]:
self.runsettings.store_separate_files=eval(str(self.inputs[‘Setup’][‘StoreSeparateFiles’]))
self.runsettings.store_everything=False if ‘StoreEverything’ in self.inputs[‘Setup’]:
self.runsettings.store_everything=eval(str(self.inputs[‘Setup’][‘StoreEverything’])) if self.runsettings.store_everything:
self.runsettings.store_outputs=True; if inputs[‘MPI’][‘Size’] > 1:
self.runsettings.all_dir=os.path.join(self.inputs[‘Setup’][‘cwd’], self.inputs[‘Setup’][‘RunName’],’All_Outputs’,’MPI_’+str(inputs[‘MPI’][‘Rank’]))
- else:
self.runsettings.all_dir=os.path.join(self.inputs[‘Setup’][‘cwd’], self.inputs[‘Setup’][‘RunName’], ‘All_Outputs’)
- if inputs[‘MPI’][‘Size’] > 1:
self.runsettings.inputs_dir = os.path.join(self.inputs[‘Setup’][‘cwd’], self.inputs[‘Setup’][‘RunName’], ‘Input_Files’,’MPI_’+str(inputs[‘MPI’][‘Rank’])) self.runsettings.output_dir = os.path.join(self.inputs[‘Setup’][‘cwd’], self.inputs[‘Setup’][‘RunName’],’Spectrum_Files’,’MPI_’+str(inputs[‘MPI’][‘Rank’]))
- else:
self.runsettings.inputs_dir = os.path.join(self.inputs[‘Setup’][‘cwd’], self.inputs[‘Setup’][‘RunName’], ‘Input_Files’) self.runsettings.output_dir = os.path.join(self.inputs[‘Setup’][‘cwd’], self.inputs[‘Setup’][‘RunName’], ‘Spectrum_Files’)
self.runsettings.output_filename=’SLHA_output’ if ‘Output File’ in self.inputs[‘Setup’]:
self.runsettings.output_filename=self.inputs[‘Setup’][‘Output File’]
- if ‘Spectrum File’ in self.inputs[‘Setup’]:
self.runsettings.spc_filename=self.inputs[‘Setup’][‘Spectrum File’]
- else:
self.runsettings.spc_filename=’SLHA_output’
## the input file should be the input for the first code that we run, presumably SPheno. Note we imported the json as an OrderedDict firstcode=next(iter(self.inputs[‘Codes’])) self.runsettings.input_filename=self.inputs[‘Codes’][firstcode][‘InputFile’] if ‘Variables’ in self.inputs:
self.runsettings.variables=self.inputs[‘Variables’] self.varnames = list(self.inputs[‘Variables’].keys()) self.runsettings.varnames=self.varnames
- else:
self.runsettings.variables=None self.varnames=None self.runsettings.varnames=None
- if ‘Derived Variables’ in self.inputs:
- “””
Allow for functions of the variables, which should be provided as a dictionary like {“dvar1”: “math.exp(mh)”, …} These will be treated like variables when writing the input files etc, but won’t show up in the csv file
“”” self.runsettings.derived_variables = self.inputs[‘Derived Variables’]
- if ‘Observables’ in self.inputs:
self.runsettings.observables=self.inputs[‘Observables’]
- if ‘Fitting’ in self.inputs:
self.runsettings.fitting_inputs=self.inputs[‘Fitting’]
bsmart.debug module
Debugging routines modified from xBit by F. Staub
- bsmart.debug.command_line_log(command, log, ctimeout=None)[source]
Execute commands in a shell, logging both the command and any errors. 22/07/2024: discard the output of stdout since we never use it.
bsmart.dmlimits module
Code to perform very basic direct detection DM limits using interpolation based on data scraped from plots.
This should ultimately be upgraded. But in any case it is largely unneeded because MicrOMEGAs can compute its own p-value.
bsmart.marginalisation module
- bsmart.marginalisation.find_a_sign_change(mindiff, max_safe_val, func, sols, start, end, ffa, ffb, minx=None, miny=None)[source]
Function is supposed to return a large value if unsafe, so we use max_safe_val
bsmart.zslha module
- class bsmart.zslha.SLHA(spc: SLHA | None = None)[source]
Bases:
object
- bsmart.zslha.read(file, separator=None, verbose=False, firstblock=None)[source]
file: SLHA file separator: e.g. ENDOFPARAMETERPOINT, in order to have multiple spectrum files concatenated into one verbose: for extra info firstblock: NEW, for reading only everything after a certain input, when e.g. it has been
appended to a file (e.g. HiggsBounds, Vevacious)