-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from ConnorStoneAstro/adderrors
Add custom errors to caskade
- Loading branch information
Showing
12 changed files
with
691 additions
and
442 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
from math import prod | ||
from textwrap import dedent | ||
|
||
|
||
class CaskadeException(Exception): | ||
"""Base class for all exceptions in Caskade.""" | ||
|
||
|
||
class GraphError(CaskadeException): | ||
"""Class for graph exceptions in Caskade.""" | ||
|
||
|
||
class NodeConfigurationError(CaskadeException): | ||
"""Class for node configuration exceptions in Caskade.""" | ||
|
||
|
||
class ParamConfigurationError(NodeConfigurationError): | ||
"""Class for parameter configuration exceptions in Caskade.""" | ||
|
||
|
||
class ParamTypeError(CaskadeException): | ||
"""Class for exceptions related to the type of a parameter in Caskade.""" | ||
|
||
|
||
class ActiveStateError(CaskadeException): | ||
"""Class for exceptions related to the active state of a node in Caskade.""" | ||
|
||
|
||
class FillDynamicParamsError(CaskadeException): | ||
"""Class for exceptions related to filling dynamic parameters in Caskade.""" | ||
|
||
|
||
class FillDynamicParamsTensorError(FillDynamicParamsError): | ||
def __init__(self, name, input_params, dynamic_params): | ||
fullnumel = sum(max(1, prod(p.shape)) for p in dynamic_params) | ||
message = dedent( | ||
f""" | ||
For flattened Tensor input, the (last) dim of the Tensor should | ||
equal the sum of all flattened dynamic params ({fullnumel}). | ||
Input params shape {input_params.shape} does not match dynamic | ||
params shape of: {name}. | ||
Registered dynamic params (name: shape): | ||
{', '.join(f"{repr(p)}: {str(p.shape)}" for p in dynamic_params)}""" | ||
) | ||
super().__init__(message) | ||
|
||
|
||
class FillDynamicParamsSequenceError(FillDynamicParamsError): | ||
def __init__(self, name, input_params, dynamic_params, dynamic_modules): | ||
message = dedent( | ||
f""" | ||
Input params length ({len(input_params)}) does not match dynamic | ||
params length ({len(dynamic_params)}) or number of dynamic | ||
modules ({len(dynamic_modules)}) of: {name}. | ||
Registered dynamic modules: | ||
{', '.join(repr(m) for m in dynamic_modules)} | ||
Registered dynamic params: | ||
{', '.join(repr(p) for p in dynamic_params)}""" | ||
) | ||
super().__init__(message) | ||
|
||
|
||
class FillDynamicParamsMappingError(FillDynamicParamsError): | ||
def __init__(self, name, children, dynamic_modules, missing_key=None, missing_param=None): | ||
if missing_key is not None: | ||
message = dedent( | ||
f""" | ||
Input params key "{missing_key}" not found in dynamic modules or children of: {name}. | ||
Registered dynamic modules: | ||
{', '.join(repr(m) for m in dynamic_modules)} | ||
Registered dynamic children: | ||
{', '.join(repr(c) for c in children.values() if c.dynamic)}""" | ||
) | ||
else: | ||
message = dedent( | ||
f""" | ||
Dynamic param "{missing_param.name}" not filled with given input params dict passed to {name}. | ||
Dynamic param parent(s): | ||
{', '.join(repr(p) for p in missing_param.parents)} | ||
Registered dynamic modules: | ||
{', '.join(repr(m) for m in dynamic_modules)} | ||
Registered dynamic children: | ||
{', '.join(repr(c) for c in children.values() if c.dynamic)}""" | ||
) | ||
super().__init__(message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.