Support

Overview

The syd.support module provides essential backend support for parameter operations within the syd framework. It includes custom exceptions and singleton classes that facilitate error handling and state management in parameter updates and initializations. This module is crucial for developers working with the syd framework, as it ensures robust and predictable behavior when parameters are added or updated. If you are just trying to use Syd for your project, you can probably ignore this module!

Singletons

The syd.support module defines two singleton classes, NoUpdate and NoInitialValue, which are used throughout the syd framework to represent specific states in parameter operations.

class syd.support.NoUpdate[source]

Bases: object

Singleton class to represent a non-update in parameter operations.

The NoUpdate singleton is used to signify that a parameter should not be updated. It is used throughout each parameter’s update_* method where updating an attribute of a parameter is optional. The reason for a singleton rather than the more conventional None is that None is a valid value for some parameters, and we want to be able to distinguish between a parameter that has not been updated and a parameter that has been updated to None.

class syd.support.NoInitialValue[source]

Bases: object

Singleton class to represent a non-initial value in parameter operations.

The NoInitialValue singleton represents the absence of an initial value for a parameter. It is used throughout each parameter’s add_* method where specifying the initial value is optional. The reason for using a singleton rather than the more conventional None is that None is a valid value for some parameters, and we want to be able to distinguish between a parameter that has not been initialized and a parameter that has been initialized to None.

Exceptions

exception syd.support.ParameterAddError(parameter_name: str, parameter_type: str, message: str = None)[source]

Bases: Exception

Exception raised when there is an error creating a new parameter.

Parameters:
  • parameter_name (str) – Name of the parameter that failed to be created

  • parameter_type (str) – Type of the parameter that failed to be created

  • message (str, optional) – Additional error details

exception syd.support.ParameterUpdateError(parameter_name: str, parameter_type: str, message: str = None)[source]

Bases: Exception

Exception raised when there is an error updating an existing parameter.

Parameters:
  • parameter_name (str) – Name of the parameter that failed to update

  • parameter_type (str) – Type of the parameter that failed to update

  • message (str, optional) – Additional error details

Warnings

exception syd.support.ParameterUpdateWarning(parameter_name: str, parameter_type: str, message: str = None)[source]

Bases: Warning

Warning raised when there is a non-critical issue updating a parameter.

Parameters:
  • parameter_name (str) – Name of the parameter that had the warning

  • parameter_type (str) – Type of the parameter

  • message – Additional warning details

syd.support.warn_parameter_update(parameter_name: str, parameter_type: str, message: str = None)[source]

Warn the user that a parameter has been updated to a value behind the scenes.

We include a specific function for firing off ParameterUpdateWarning warnings so that it is easier to suppress the warnings if desired.

High-level Parameter Handling

class syd.support.ParameterMeta(name, bases, namespace)[source]

Bases: ABCMeta

The ParameterMeta class is a metaclass that is used to stereotype the parameter classes. Syd often checks if an object is of a particular parameter type, and will raise an error when it isn’t. This is a nightmare for module reloading in jupyter notebooks, which is one of the primary use areas for Syd. So, the ParameterMeta class is used to store the parameter types in a way that makes sure module reloading doesn’t break the type checking.

syd.support.get_parameter_attributes(param_class) List[str][source]

Get all valid attributes for a parameter class.

Parameters:

param_class (class) – The parameter class to inspect

Returns:

Names of all valid attributes for the parameter class

Return type:

list of str

The get_parameter_attributes function is used to get the attributes of a parameter. It is used for checking parameter updates and for testing.