sweep_base
Module Contents
Classes
An attribute descriptor for declaring parameters. |
Functions
|
Generate a string description of a variable |
Attributes
- sweep_base.describe_variable(v: param.Parameterized, debug: bool, include_samples: bool, value=None) List[str]
Generate a string description of a variable
- Parameters:
v (param.Parameterized) – parameter to describe
debug (bool) – Generate a reduced number of samples from the variable
include_samples (bool) – Include a description of the samples
- Returns:
String description of the variable
- Return type:
str
- class sweep_base.SweepBase(default=None, *, doc=None, label=None, precedence=None, instantiate=False, constant=False, readonly=False, pickle_default_value=True, allow_None=False, per_instance=True, allow_refs=False, nested_refs=False)
Bases:
param.Parameter
An attribute descriptor for declaring parameters.
Parameters are a special kind of class attribute. Setting a Parameterized class attribute to be a Parameter instance causes that attribute of the class (and the class’s instances) to be treated as a Parameter. This allows special behavior, including dynamically generated parameter values, documentation strings, constant and read-only parameters, and type or range checking at assignment time.
For example, suppose someone wants to define two new kinds of objects Foo and Bar, such that Bar has a parameter delta, Foo is a subclass of Bar, and Foo has parameters alpha, sigma, and gamma (and delta inherited from Bar). She would begin her class definitions with something like this:
class Bar(Parameterized): delta = Parameter(default=0.6, doc='The difference between steps.') ... class Foo(Bar): alpha = Parameter(default=0.1, doc='The starting value.') sigma = Parameter(default=0.5, doc='The standard deviation.', constant=True) gamma = Parameter(default=1.0, doc='The ending value.') ...
Class Foo would then have four parameters, with delta defaulting to 0.6.
Parameters have several advantages over plain attributes:
Parameters can be set automatically when an instance is constructed: The default constructor for Foo (and Bar) will accept arbitrary keyword arguments, each of which can be used to specify the value of a Parameter of Foo (or any of Foo’s superclasses). E.g., if a script does this:
myfoo = Foo(alpha=0.5)
myfoo.alpha will return 0.5, without the Foo constructor needing special code to set alpha.
If Foo implements its own constructor, keyword arguments will still be accepted if the constructor accepts a dictionary of keyword arguments (as in
def __init__(self,**params):
), and then each class calls its superclass (as insuper(Foo,self).__init__(**params)
) so that the Parameterized constructor will process the keywords.A Parameterized class need specify only the attributes of a Parameter whose values differ from those declared in superclasses; the other values will be inherited. E.g. if Foo declares:
delta = Parameter(default=0.2)
the default value of 0.2 will override the 0.6 inherited from Bar, but the doc will be inherited from Bar.
The Parameter descriptor class can be subclassed to provide more complex behavior, allowing special types of parameters that, for example, require their values to be numbers in certain ranges, generate their values dynamically from a random distribution, or read their values from a file or other external source.
The attributes associated with Parameters provide enough information for automatically generating property sheets in graphical user interfaces, allowing Parameterized instances to be edited by users.
Note that Parameters can only be used when set as class attributes of Parameterized classes. Parameters used as standalone objects, or as class attributes of non-Parameterized classes, will not have the behavior described here.
- abstract values(debug: bool) List[Any]
All sweep classes must implement this method. This generates sample values from based on the parameters bounds and sample number.
- Parameters:
debug (bool) – Return a reduced set of samples to enable fast debugging of a data generation and plotting pipeline. Ideally when debug is true, 2 samples will be returned
- Returns:
A list of samples from the variable
- Return type:
List[Any]
- hash_persistent() str
A hash function that avoids the PYTHONHASHSEED ‘feature’ which returns a different hash value each time the program is run
- sampling_str(debug=False) str
Generate a string representation of the of the sampling procedure
- Parameters:
debug (bool) – If true then self.samples_debug is used
- as_slider(debug=False) panel.widgets.slider.DiscreteSlider
given a sweep variable (self), return the range of values as a panel slider
- Parameters:
debug (bool, optional) – pass to the sweepvar to produce a full set of varaibles, or when debug=True, a reduces number of sweep vars. Defaults to False.
- Returns:
A panel slider with the values() of the sweep variable
- Return type:
pn.widgets.slider.DiscreteSlider
- as_dim(compute_values=False, debug=False) holoviews.Dimension
Takes a sweep variable and turns it into a holoview dimension
- Return type:
hv.Dimension
- indices_to_samples(desires_num_samples, sample_values)
- with_const(const_value: Any) Tuple[SweepBase, Any]
Create a new instance of SweepBase with a constant value.
- Parameters:
const_value (Any) – The constant value to be associated with the new instance.
- Returns:
A tuple containing the new instance of SweepBase and the constant value.
- Return type:
Tuple[SweepBase, Any]