modelspec.base_types.Base

class modelspec.base_types.Base[source]

Bases: object

Base class for all object in a model specification. Any object should inherit from this class.

Method generated by attrs for class Base.

Methods

from_bson(bson_str)

Instantiate an modelspec object from a BSON string

from_bson_file(filename)

Create a Base from its BSON representation stored in a file.

from_dict(d)

Instantiate an Base object from a dictionary

from_file(filename)

Create a Base from its representation stored in a file.

from_json(json_str)

Instantiate an modelspec object from a JSON string

from_json_file(filename)

Create a Base from its JSON representation stored in a file.

from_xml(xml_str)

Instantiate a Base object from an XML string

from_xml_file(filename)

Create a Base from its XML representation stored in a file.

from_yaml(yaml_str)

Instantiate an modelspec object from a YAML string

from_yaml_file(filename)

Create a Base from its YAML representation stored in a file.

generate_documentation([format])

Generate documentation for the modelspec object.

get_child(id, type_)

Get a child object from the model specification.

to_bson()

Convert the Base object to a BSON string representation.

to_bson_file(filename[, include_metadata])

Convert modelspec format to bson format

to_dict()

Convert the Base object to a nested dict structure.

to_json()

Convert the Base object to a JSON string representation.

to_json_file([filename, include_metadata])

Convert the modelspec model to JSON format and save to a file.

to_xml()

Convert the data dictionary to an XML string representation using the ElementTree library.

to_xml_file([filename, include_metadata])

to_yaml([include_metadata])

Convert the Base object to a YAML dictionary representation.

to_yaml_file([filename, include_metadata])

Convert modelspec format to yaml format

to_dict() Dict[str, Any][source]

Convert the Base object to a nested dict structure.

to_json() str[source]

Convert the Base object to a JSON string representation.

to_bson() str[source]

Convert the Base object to a BSON string representation.

to_xml() str[source]

Convert the data dictionary to an XML string representation using the ElementTree library.

classmethod from_dict(d: Dict[str, Any]) Base[source]

Instantiate an Base object from a dictionary

classmethod from_yaml(yaml_str: str) Base[source]

Instantiate an modelspec object from a YAML string

classmethod from_json(json_str: str) Base[source]

Instantiate an modelspec object from a JSON string

classmethod from_bson(bson_str: str) Base[source]

Instantiate an modelspec object from a BSON string

classmethod from_xml(xml_str: str) Base[source]

Instantiate a Base object from an XML string

to_json_file(filename: str | None = None, include_metadata: bool = True) str[source]

Convert the modelspec model to JSON format and save to a file.

Note

JSON is standard file format uses human-readable text to store and transmit data objects consisting of

attribute–value pairs and arrays

Parameters:
  • filename – The name of the file to save. If None, use f"{self.id}.json"

  • include_metadata – Contains contact information, citations, acknowledgements, pointers to sample data, benchmark results, and environments in which the specified model was originally implemented

Returns:

The name of the generated JSON file

to_bson_file(filename: str, include_metadata: bool = True) str[source]

Convert modelspec format to bson format

Parameters:
  • filename – File in modelspec format (Filename extension: .bson )

  • include_metadata – Contains contact information, citations, acknowledgements, pointers to sample data, benchmark results, and environments in which the specified model was originally implemented

Returns:

The name of the generated bson file

to_yaml(include_metadata: bool = True) str[source]

Convert the Base object to a YAML dictionary representation.

Parameters:

include_metadata – Should metadata be included in the YAML output?

Returns:

A YAML string representation of the object.

to_yaml_file(filename: str | None = None, include_metadata: bool | None = True) str[source]

Convert modelspec format to yaml format

Parameters:
  • filename – File in modelspec format (Filename extension: .yaml). If None, use f"{self.id}.yaml"

  • include_metadata – Contains contact information, citations, acknowledgements, pointers to sample data, benchmark results, and environments in which the specified model was originally implemented

Returns:

The name of the generated yaml file

classmethod from_file(filename: str) Base[source]

Create a Base from its representation stored in a file. Auto-detect the correct deserialization code based on file extension. Currently supported formats are; JSON(.json) and YAML (.yaml or .yml)

Parameters:

filename – The name of the file to load.

Returns:

An modelspec Base for this file.

classmethod from_json_file(filename: str) Base[source]

Create a Base from its JSON representation stored in a file.

Parameters:

filename – The file from which to load the JSON data.

Returns:

An modelspec Base for this JSON

classmethod from_bson_file(filename: str) Base[source]

Create a Base from its BSON representation stored in a file.

Parameters:

filename – The file from which to load the BSON data.

Returns:

An modelspec Base for this BSON

classmethod from_yaml_file(filename: str) Base[source]

Create a Base from its YAML representation stored in a file.

Parameters:

filename – The file from which to load the YAML data.

Returns:

An modelspec Base for this YAML

classmethod from_xml_file(filename: str) Base[source]

Create a Base from its XML representation stored in a file.

Parameters:

filename – The file from which to load the XML data.

Returns:

A modelspec Base for this XML.

get_child(id: str, type_: str) Any[source]

Get a child object from the model specification.

Parameters:
  • id – The unique string identifier of the child object.

  • type – The type of the child object. Must be an attribute name that contains a list of child objects with id attributes..

Returns:

The child object. If the child object is not found, None is returned.

property definition: str

The definition of the model.

Returns:

The definition of the model.

property allowed_fields: Dict[str, Tuple[str, Any]]

Get the list of allowed fields for this model.

Returns:

The allowed fields are returned as dict keyed by field name

and with values of tuple with (field_description, field_type).

property allowed_children: Dict[str, Tuple[str, Any]]

Get the list of allowed children for this model. Children are defined as any attribute of this object that is a collection of objects that inherits from Base.

Returns:

The allowed children are returned as dict keyed attribute name of the collection

and with values of tuple with (description, type).

generate_documentation(format: str = 'markdown') str[source]

Generate documentation for the modelspec object.

Parameters:

format – The format to generate the documentation in. Currently supported formats are: [‘markdown’, ‘dict’]