utilities#
Exceptions:
|
Raised when the referenced object does not exist in the input file. |
|
Raised when an object can't be printed out due to an illegal state. |
Warning for when a field or line expands that may damage user formatting. |
|
Raised when non-comment inputs exceed the allowed line length in an input. |
|
|
Raised when there is an error with the MCNP input not related to the parser. |
Raised when there is a possible, but not fatal error with the MCNP input not related to the parser. |
|
|
Raised when there is a conflict in number spaces |
|
Raised when there is an error parsing the MCNP input at the SLY parsing layer. |
|
Raised when data for importance data for a particle in the problem is not provided for a cell. |
|
Raised when data, such as cell importance or tally type, are set for a particle type not in the problem's mode. |
|
Base class for incongruencies between particle types in problem mode, cell importances, and tallies |
|
Raised when multiple conflicting parameters are given. |
|
Raised when the constants of a Surface are non-conform, but do not raise an error with MCNP. |
Raised when additional blocks exist after the default data block. |
|
|
Raised when an undefined element is used. |
|
Raised when MCNP syntax that is not supported is found |
Functions:
|
Adds additional context to an Exception raised by an |
|
A function decorator that enforces type annotations for the function when ran. |
|
Attempts to convert a FORTRAN formatted float string to a float. |
|
Determines if the line is a |
|
A decorator function that makes a property based off of a pointer to another object. |
|
A decorator function for making a property from a ValueNode. |
|
Marks a function as needed having the abstract syntax tree. |
|
Marks a function as needed having the concrete syntax tree. |
|
Marks a function, and turns it into a property that is an object pointer to a collection ( |
|
Marks a function, and turns it into a property that is an object pointer ( |
- exception montepy.utilities.BrokenObjectLinkError(parent_type, parent_number, child_type, child_number)#
Bases:
MalformedInputErrorRaised when the referenced object does not exist in the input file.
Methods:
Exception.add_note(note) -- add a note to the exception
Exception.with_traceback(tb) -- set self.__traceback__ to tb and return self.
Attributes:
- add_note()#
Exception.add_note(note) – add a note to the exception
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- args#
- exception montepy.utilities.IllegalState(message)#
Bases:
ValueErrorRaised when an object can’t be printed out due to an illegal state.
Methods:
Exception.add_note(note) -- add a note to the exception
Exception.with_traceback(tb) -- set self.__traceback__ to tb and return self.
Attributes:
- add_note()#
Exception.add_note(note) – add a note to the exception
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- args#
- exception montepy.utilities.LineExpansionWarning#
Bases:
WarningWarning for when a field or line expands that may damage user formatting.
Methods:
Exception.add_note(note) -- add a note to the exception
Exception.with_traceback(tb) -- set self.__traceback__ to tb and return self.
Attributes:
- add_note()#
Exception.add_note(note) – add a note to the exception
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- args#
- exception montepy.utilities.LineOverRunWarning#
Bases:
UserWarningRaised when non-comment inputs exceed the allowed line length in an input.
Methods:
Exception.add_note(note) -- add a note to the exception
Exception.with_traceback(tb) -- set self.__traceback__ to tb and return self.
Attributes:
- add_note()#
Exception.add_note(note) – add a note to the exception
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- args#
- exception montepy.utilities.MalformedInputError(input, message)#
Bases:
ValueErrorRaised when there is an error with the MCNP input not related to the parser.
Methods:
Exception.add_note(note) -- add a note to the exception
Exception.with_traceback(tb) -- set self.__traceback__ to tb and return self.
Attributes:
- add_note()#
Exception.add_note(note) – add a note to the exception
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- args#
- exception montepy.utilities.MalformedInputWarning#
Bases:
UserWarningRaised when there is a possible, but not fatal error with the MCNP input not related to the parser.
Methods:
Exception.add_note(note) -- add a note to the exception
Exception.with_traceback(tb) -- set self.__traceback__ to tb and return self.
Attributes:
- add_note()#
Exception.add_note(note) – add a note to the exception
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- args#
- exception montepy.utilities.NumberConflictError(message)#
Bases:
ExceptionRaised when there is a conflict in number spaces
Methods:
Exception.add_note(note) -- add a note to the exception
Exception.with_traceback(tb) -- set self.__traceback__ to tb and return self.
Attributes:
- add_note()#
Exception.add_note(note) – add a note to the exception
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- args#
- exception montepy.utilities.ParsingError(input, message, error_queue)#
Bases:
MalformedInputErrorRaised when there is an error parsing the MCNP input at the SLY parsing layer.
Methods:
Exception.add_note(note) -- add a note to the exception
Exception.with_traceback(tb) -- set self.__traceback__ to tb and return self.
Attributes:
- add_note()#
Exception.add_note(note) – add a note to the exception
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- args#
- exception montepy.utilities.ParticleTypeNotInCell(message)#
Bases:
ParticleTypeWarningRaised when data for importance data for a particle in the problem is not provided for a cell.
Methods:
Exception.add_note(note) -- add a note to the exception
Exception.with_traceback(tb) -- set self.__traceback__ to tb and return self.
Attributes:
- add_note()#
Exception.add_note(note) – add a note to the exception
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- args#
- exception montepy.utilities.ParticleTypeNotInProblem(message)#
Bases:
ParticleTypeWarningRaised when data, such as cell importance or tally type, are set for a particle type not in the problem’s mode.
Methods:
Exception.add_note(note) -- add a note to the exception
Exception.with_traceback(tb) -- set self.__traceback__ to tb and return self.
Attributes:
- add_note()#
Exception.add_note(note) – add a note to the exception
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- args#
- exception montepy.utilities.ParticleTypeWarning(message)#
Bases:
WarningBase class for incongruencies between particle types in problem mode, cell importances, and tallies
Methods:
Exception.add_note(note) -- add a note to the exception
Exception.with_traceback(tb) -- set self.__traceback__ to tb and return self.
Attributes:
- add_note()#
Exception.add_note(note) – add a note to the exception
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- args#
- exception montepy.utilities.RedundantParameterSpecification(key, new_value)#
Bases:
ValueErrorRaised when multiple conflicting parameters are given.
e.g.,
1 0 -1 imp:n=5 imp:n=0Methods:
Exception.add_note(note) -- add a note to the exception
Exception.with_traceback(tb) -- set self.__traceback__ to tb and return self.
Attributes:
- add_note()#
Exception.add_note(note) – add a note to the exception
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- args#
- exception montepy.utilities.SurfaceConstantsWarning(message)#
Bases:
UserWarningRaised when the constants of a Surface are non-conform, but do not raise an error with MCNP.
Methods:
Exception.add_note(note) -- add a note to the exception
Exception.with_traceback(tb) -- set self.__traceback__ to tb and return self.
Attributes:
- add_note()#
Exception.add_note(note) – add a note to the exception
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- args#
- exception montepy.utilities.UndefinedBlock#
Bases:
UserWarningRaised when additional blocks exist after the default data block.
Methods:
Exception.add_note(note) -- add a note to the exception
Exception.with_traceback(tb) -- set self.__traceback__ to tb and return self.
Attributes:
- add_note()#
Exception.add_note(note) – add a note to the exception
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- args#
- exception montepy.utilities.UnknownElement(missing_val)#
Bases:
ValueErrorRaised when an undefined element is used.
Methods:
Exception.add_note(note) -- add a note to the exception
Exception.with_traceback(tb) -- set self.__traceback__ to tb and return self.
Attributes:
- add_note()#
Exception.add_note(note) – add a note to the exception
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- args#
- exception montepy.utilities.UnsupportedFeature(message, input=None, error_queue=None)#
Bases:
ParsingErrorRaised when MCNP syntax that is not supported is found
Methods:
Exception.add_note(note) -- add a note to the exception
Exception.with_traceback(tb) -- set self.__traceback__ to tb and return self.
Attributes:
- add_note()#
Exception.add_note(note) – add a note to the exception
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- args#
- montepy.utilities.add_line_number_to_exception(error, broken_robot)#
Adds additional context to an Exception raised by an
MCNP_Object.This will add the line, file name, and the input lines to the error.
- Parameters:
error (Exception) – The error that was raised.
broken_robot (MCNP_Object) – The parent object that had the error raised.
- Raises:
Exception – … that’s the whole point.
- montepy.utilities.args_checked(func: Callable)#
A function decorator that enforces type annotations for the function when ran.
This will read the type annotations for all arguments and enforce that the argument is of that type at run-time. Value restrictions can also be applied as well with
typing.Annotated.Examples
This will ensure that all arguments have to be an integer,
>>> from montepy.utilities import * >>> import montepy.types as ty >>> >>> @args_checked ... def foo(a: int) -> int: ... return a >>> print(foo(1)) 1 >>> print(foo("a")) Traceback (most recent call last): ... TypeError: Unable to set "a" for "foo" to "a" which is not of type "int"
Values can be checked as by using
typing.Annotatedto add an annotation of the values that are allowed (via a special value checking function),>>> import typing >>> import montepy.types as ty >>> >>> @args_checked ... def bar(a: typing.Annotated[int, ty.positive]) -> int: ... return a >>> print(bar(1)) 1 >>> print(bar(0)) Traceback (most recent call last): ... ValueError: Unable to set "a" for "bar" to "0" since it is less than or equal to "0"
- Parameters:
func (
Callable) – The function to decorate- Returns:
A decorated function that will do type and value checking at run time based on the annotation.
- Return type:
Callable
- Raises:
TypeError – If an argument of the wrong type is provided
ValueError – If an argument of the right type, but wrong value is given.
- montepy.utilities.fortran_float(number_string: str | Real)#
Attempts to convert a FORTRAN formatted float string to a float.
FORTRAN allows silly things for scientific notation like
6.02+23to represent Avogadro’s Number.- Parameters:
number_string (
str|Real) – the string that will be converted to a float- Raises:
ValueError – If the string can not be parsed as a float.
- Returns:
the parsed float of the this string
- Return type:
- montepy.utilities.make_prop_pointer(hidden_param, types=None, base_type=None, validator=None, deletable=False)#
A decorator function that makes a property based off of a pointer to another object.
Note this can also be used for almost any circumstance as everything in python is a pointer.
- Parameters:
hidden_param (str) – The string representing the parameter name of the internally stored ValueNode.
types (type, tuple) – the acceptable types for the settable, which is passed to isinstance, if an empty tuple is provided the type will be self.
validator (collections.abc.Callable) – A validator function to run on values before setting. Must accept func(self, value).
deletable (bool) – If true make this property deletable. When deleted the value will be set to None.
- montepy.utilities.make_prop_val_node(hidden_param, types=None, base_type=None, validator=None, deletable=False)#
A decorator function for making a property from a ValueNode.
This decorator is meant to handle all boiler plate. It will get and set the value property of the underlying ValueNode. By default the property is not settable unless types is set.
- Parameters:
hidden_param (str) – The string representing the parameter name of the internally stored ValueNode.
types (type, tuple) – the acceptable types for the settable, which is passed to isinstance. If an empty tuple will be type(self).
validator (collections.abc.Callable) – A validator function to run on values before setting. Must accept func(self, value).
deletable (bool) – If true make this property deletable. When deleted the value will be set to None.
- montepy.utilities.needs_full_ast(func)#
Marks a function as needed having the abstract syntax tree.
Calling a marked function will lead to a full (abstract) parse.
- montepy.utilities.needs_full_cst(func)#
Marks a function as needed having the concrete syntax tree.
Calling a marked function will lead to a full parse.
- montepy.utilities.prop_pointer_collect_from_problem(hidden_param: str, ids_param: str, prob_collection_param: str, collect_type: type, types: tuple[type] = None, base_type: type = None, validator: Callable = None, deletable: bool = False)#
Marks a function, and turns it into a property that is an object pointer to a collection (
make_prop_pointer()), which can be pulled from the problem automatically.When this property is not populated, and a problem is linked, the object is fetched from the problem. This differs from
prop_pointer_from_problem()because this stores multiple objects.- Parameters:
hidden_param (
str) – the _private attribute where the object is stored.id_param (str) – the parameter of the ID number for the object to pull.
prob_collection_param (
str) – the parameter of the problem of the collection, from which to grab this object from.types (
tuple[type]) – the allowed types for making this property settable.base_type (
type) – the type to coerce all other types to.validator (
Callable) – A function to call on setting for additional validationdeletable (
bool) – Whether deletion should be allowed.ids_param (str)
collect_type (type)
- Raises:
BrokenObjectLinkError – When the object can not be found.
- montepy.utilities.prop_pointer_from_problem(hidden_param: str, id_param: str, prob_collection_param: str, types: tuple[type] = None, base_type: type = None, validator: Callable = None, deletable: bool = False)#
Marks a function, and turns it into a property that is an object pointer (
make_prop_pointer()), which can be pulled from the problem automatically.When this property is not populated, and a problem is linked, the object is fetched from the problem.
- Parameters:
hidden_param (
str) – the _private attribute where the object is stored.id_param (
str) – the parameter of the ID number for the object to pull.prob_collection_param (
str) – the parameter of the problem of the collection, from which to grab this object from.types (
tuple[type]) – the allowed types for making this property settable.base_type (
type) – the type to coerce all other types to.validator (
Callable) – A function to call on setting for additional validationdeletable (
bool) – Whether deletion should be allowed.
- Raises:
BrokenObjectLinkError – When the object can not be found.