Skip to content

Commit

Permalink
Add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
dhadka committed Sep 10, 2024
1 parent c00f8c7 commit b2419f6
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions rhodium/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@
LogNormalUncertainty, Direction

class UnnamedObject(metaclass=ABCMeta):
"""Base class for model components not yet assigned a name.
Rhodium has the concept of a `NamedObject`, which simply means a name is
associated with an object, typically one of Rhodium's classes like `Lever`
or `Uncertainty`. But when using decorators to construct a model, the
name is derived from the keyword arguments to a function, which are not
known until we can inspect the function. Thus, this class represents the
`NamedObject` before it is assigned a name.
Parameters
----------
constructor : Callable
The constructor that converts this unnamed object into a named object
"""

def __init__(self, constructor, *args, **kwargs):
self.constructor = constructor
Expand All @@ -34,31 +48,37 @@ def convert(self, name):
return self.constructor(name, *self.args, **self.kwargs)

class Real(UnnamedObject):
"""Construct a `RealLever` using the decorator approach."""

def __init__(self, *args, **kwargs):
super().__init__(RealLever, *args, **kwargs)

class Integer(UnnamedObject):
"""Construct a `IntegerLever` using the decorator approach."""

def __init__(self, *args, **kwargs):
super().__init__(IntegerLever, *args, **kwargs)

class Categorical(UnnamedObject):
"""Construct a `CategoricalLever` using the decorator approach."""

def __init__(self, *args, **kwargs):
super().__init__(CategoricalLever, *args, **kwargs)

class Permutation(UnnamedObject):
"""Construct a `PermutationLever` using the decorator approach."""

def __init__(self, *args, **kwargs):
super().__init__(PermutationLever, *args, **kwargs)

class Subset(UnnamedObject):
"""Construct a `SubsetLever` using the decorator approach."""

def __init__(self, *args, **kwargs):
super().__init__(SubsetLever, *args, **kwargs)

class Uniform(float, UnnamedObject):
"""Construct a `UniformUncertainty` using the decorator approach."""

def __init__(self, *args, **kwargs):
super().__init__(UniformUncertainty, *args, **kwargs)
Expand All @@ -67,6 +87,7 @@ def __new__(cls, *args, **kwargs):
return float.__new__(cls, kwargs.get("default_value", float("NaN")))

class Normal(float, UnnamedObject):
"""Construct a `NormalUncertainty` using the decorator approach."""

def __init__(self, *args, **kwargs):
super().__init__(NormalUncertainty, *args, **kwargs)
Expand All @@ -75,6 +96,7 @@ def __new__(cls, *args, **kwargs):
return float.__new__(cls, kwargs.get("default_value", float("NaN")))

class LogNormal(float, UnnamedObject):
"""Construct a `LogNormalUncertainty` using the decorator approach."""

def __init__(self, *args, **kwargs):
super().__init__(LogNormalUncertainty, *args, **kwargs)
Expand Down

0 comments on commit b2419f6

Please sign in to comment.