Node
A pipeline consists of Node
s, which hold
the various attributes required to build a pipeline, such as the
.item
, its .space
,
its .config
and so on.
The Node
s are connected to each in a parent-child
relation ship where the children are simply the .nodes
that the parent leads to.
To give these attributes and relations meaning, there are various subclasses
of Node
which give different syntactic meanings
when you want to construct something like a
search_space()
or
build()
some concrete object out of the
pipeline.
For example, a Sequential
node
gives the meaning that each of its children in
.nodes
should follow one another while
something like a Choice
gives the meaning that only one of its children should be chosen.
You will likely never have to create a Node
directly, but instead use the various components to create the pipeline.
Hashing
When hashing a node, i.e. to put it in a set
or as a key in a dict
,
only the name of the node and the hash of its children is used.
This means that two nodes with the same connectivity will be equalling hashed,
Equality
When considering equality, this will be done by comparing all the fields
of the node. This include even the parent
and branches
fields. This
means two nodes are considered equal if they look the same and they are
connected in to nodes that also look the same.
class RichOptions
#
class ParamRequest
dataclass
#
Bases: Generic[T]
A parameter request for a node. This is most useful for things like seeds.
key: str
attr
#
The key to request under.
default: T | object
classvar
attr
#
The default value to use if the key is not found.
If left as _NotSet
(default) then an error will be raised if the
parameter is not found during configuration with
configure()
.
has_default: bool
prop
#
Whether this request has a default value.
class Node(*nodes, name, item=None, config=None, space=None, fidelities=None, config_transform=None, meta=None)
dataclass
#
Bases: RichRenderable
, Generic[Item, Space]
The core node class for the pipeline.
These are simple objects that are named and linked together to form
a chain. They are then wrapped in a Pipeline
object to provide
a convenient interface for interacting with the chain.
Source code in src/amltk/pipeline/node.py
name: str
classvar
attr
#
Name of the node
item: Callable[..., Item] | Item | None
classvar
attr
#
The item attached to this node
nodes: tuple[Node, ...]
classvar
attr
#
The nodes that this node leads to.
config: Config | None
classvar
attr
#
The configuration for this node
space: Space | None
classvar
attr
#
The search space for this node
fidelities: Mapping[str, Any] | None
classvar
attr
#
The fidelities for this node
config_transform: Callable[[Config, Any], Config] | None
classvar
attr
#
A function that transforms the configuration of this node
meta: Mapping[str, Any] | None
classvar
attr
#
Any meta information about this node
RICH_OPTIONS: RichOptions
classvar
#
Options for rich printing
def __getitem__(key)
#
Get the node with the given name.
Source code in src/amltk/pipeline/node.py
def configure(config, *, prefixed_name=None, transform_context=None, params=None)
#
Configure this node and anything following it with the given config.
PARAMETER | DESCRIPTION |
---|---|
config |
The configuration to apply
TYPE:
|
prefixed_name |
Whether items in the config are prefixed by the names
of the nodes.
* If
TYPE:
|
transform_context |
Any context to give to
TYPE:
|
params |
The params to match any requests when configuring this node. These will match against any ParamRequests in the config and will be used to fill in any missing values. |
RETURNS | DESCRIPTION |
---|---|
Self
|
The configured node |
Source code in src/amltk/pipeline/node.py
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 |
|
def fidelity_space()
#
Get the fidelities for this node and any connected nodes.
def linearized_fidelity(value)
#
Get the liniearized fidelities for this node and any connected nodes.
PARAMETER | DESCRIPTION |
---|---|
value |
The value to linearize. Must be between [0, 1]
TYPE:
|
Return
dictionary from key to it's linearized fidelity.
Source code in src/amltk/pipeline/node.py
def iter()
#
Iterate the the nodes, including this node.
YIELDS | DESCRIPTION |
---|---|
Node
|
The nodes connected to this node |
def mutate(**kwargs)
#
Mutate the node with the given keyword arguments.
PARAMETER | DESCRIPTION |
---|---|
**kwargs |
The keyword arguments to mutate
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
Self The mutated node |
Source code in src/amltk/pipeline/node.py
def copy()
#
def path_to(key)
#
Find a path to the given node.
PARAMETER | DESCRIPTION |
---|---|
key |
The key to search for or a function that returns True if the node is the desired node |
RETURNS | DESCRIPTION |
---|---|
list[Node] | None
|
The path to the node if found, else None |
Source code in src/amltk/pipeline/node.py
def walk(path=None)
#
Walk the nodes in this chain.
PARAMETER | DESCRIPTION |
---|---|
path |
The current path to this node |
YIELDS | DESCRIPTION |
---|---|
list[Node]
|
The parents of the node and the node itself |
Source code in src/amltk/pipeline/node.py
def find(key, default=None)
#
Find a node in that's nested deeper from this node.
PARAMETER | DESCRIPTION |
---|---|
key |
The key to search for or a function that returns True if the node is the desired node |
default |
The value to return if the node is not found. Defaults to None
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Node | T | None
|
The node if found, otherwise the default value. Defaults to None |
Source code in src/amltk/pipeline/node.py
def search_space(parser, *parser_args, **parser_kwargs)
#
Get the search space for this node.
PARAMETER | DESCRIPTION |
---|---|
parser |
The parser to use. This can be a function that takes in the node and returns the search space or a string that is one of:
TYPE:
|
parser_args |
The positional arguments to pass to the parser
TYPE:
|
parser_kwargs |
The keyword arguments to pass to the parser
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ParserOutput | ConfigurationSpace | OptunaSearchSpace
|
The search space |
Source code in src/amltk/pipeline/node.py
def build(builder, *builder_args, **builder_kwargs)
#
Build a concrete object out of this node.
PARAMETER | DESCRIPTION |
---|---|
builder |
The builder to use. This can be a function that takes in the node and returns the object or a string that is one of:
TYPE:
|
builder_args |
The positional arguments to pass to the builder
TYPE:
|
builder_kwargs |
The keyword arguments to pass to the builder
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
BuilderOutput | Pipeline
|
The built object |
Source code in src/amltk/pipeline/node.py
def request(key, default=_NotSet)
#
Create a new parameter request.
PARAMETER | DESCRIPTION |
---|---|
key |
The key to request under.
TYPE:
|
default |
The default value to use if the key is not found.
If left as
TYPE:
|