schrodinger.models.yaml_utils module

Utility functions for converting CompoundParam to/from YAML format.

In addition to simply serializing/deserializing CompoundParam objects, these utility functions support the concept of “versioning” CompoundParam objects. See the adapter decorator in schrodinger.models.json for more information on versioning.

Example usage:

>>> class Contact(CompoundParam):
...     first_name: str
...     last_name: str
...     age: int
...
>>> contact = Contact(first_name='John', last_name='Doe', age=30)
>>> yaml_str = param_to_yaml_str(contact)
>>> imported_contact = yaml_str_to_param(yaml_str, Contact)
schrodinger.models.yaml_utils.param_to_yaml_str(param: schrodinger.models.parameters.CompoundParam, exclude_private: bool = False) str

Convert a CompoundParam object to a YAML string. The YAML string will encode version information so that it can still be used with future versions of the CompoundParam class.

Parameters
  • param – the ComoundParam object to convert

  • exclude_private – whether subparams with names starting with ‘_’ should be excluded from the yaml string

schrodinger.models.yaml_utils.yaml_str_to_param(yaml_str: str, param_cls: type) schrodinger.models.parameters.CompoundParam

Convert a YAML string to a CompoundParam object of the type specified by param_cls. If the YAML string contains version information, version adapter methods in the CompoundParam class will be used so older YAML strings can be converted to newer CompoundParam objects.

Parameters
  • yaml_str – the YAML string to convert

  • param_cls – the class of the CompoundParam object to create

schrodinger.models.yaml_utils.param_to_yaml_file(param: schrodinger.models.parameters.CompoundParam, file_path: str, exclude_private: bool = False)

Write a CompoundParam object to the YAML file specified by file_path. For more information, see param_to_yaml_str.

schrodinger.models.yaml_utils.yaml_file_to_param(file_path: str, param_cls: type) schrodinger.models.parameters.CompoundParam

Read a CompoundParam object from the YAML file specified by file_path. For more information, see yaml_str_to_param.