ersilia.io package

Subpackages

Submodules

ersilia.io.annotated module

class ersilia.io.annotated.AnnotatedDataTyper(data, annotated_type, annotated_shape)[source]

Bases: object

Class to determine the type of annotated data.

Parameters:
  • data (any) – The annotated data.

  • annotated_type (str) – The type of the annotated data (e.g., “String”, “Float”, “Integer”).

  • annotated_shape (str) – The shape of the annotated data (e.g., “Single”, “List”, “Flexible List”).

get_type()[source]

Get the type of the annotated data.

Returns:

Dictionary containing the type and shape of the annotated data, or None if the type is not recognized.

Return type:

dict or None

ersilia.io.dataframe module

class ersilia.io.dataframe.Dataframe(keys=None, inputs=None, texts=None, values=None, features=None)[source]

Bases: object

Class to handle data in a dataframe-like structure.

Parameters:
  • keys (list, optional) – List of keys.

  • inputs (list, optional) – List of inputs.

  • texts (list, optional) – List of texts.

  • values (list, optional) – List of values.

  • features (list, optional) – List of features.

from_csv(filename)[source]

Load data from a CSV file.

Parameters:

filename (str) – Path to the CSV file.

Return type:

None

iterrows()[source]

Iterate over the rows of the dataframe.

Yields:

dict – Dictionary representing a row in the dataframe.

ersilia.io.input module

class ersilia.io.input.BaseIOGetter(config_json=None)[source]

Bases: ErsiliaBase

Base class to get IO handlers based on model or specifications.

Parameters:

config_json (dict, optional) – Configuration JSON.

get(model_id=None, input_type=None, input_shape=None)[source]

Get the IO handler based on model or specifications.

Parameters:
  • model_id (str, optional) – Model identifier.

  • input_type (str, optional) – Input type.

  • input_shape (str, optional) – Input shape.

Returns:

IO handler object.

Return type:

IO

shape(model_id)[source]

Get the input shape from the model card.

Parameters:

model_id (str) – Model identifier.

Returns:

Input shape object.

Return type:

InputShape

class ersilia.io.input.ExampleGenerator(model_id, config_json=None)[source]

Bases: ErsiliaBase

Class to generate examples for a model.

Parameters:
  • model_id (str) – Model identifier.

  • config_json (dict, optional) – Configuration JSON.

check_model_id(**kwargs)
example(n_samples, file_name, simple, try_predefined)[source]

Generate example data.

Parameters:
  • n_samples (int) – Number of samples to generate.

  • file_name (str) – File name to save the examples.

  • simple (bool) – Whether to generate simple examples.

  • try_predefined (bool) – Whether to try predefined examples first.

Returns:

List of example data or file content if saved to file.

Return type:

list or str

predefined_example(file_name)[source]

Get predefined example data.

Parameters:

file_name (str) – File name to save the examples.

Returns:

True if predefined examples are available, False otherwise.

Return type:

bool

random_example(n_samples, file_name, simple)[source]

Generate random example data.

Parameters:
  • n_samples (int) – Number of samples to generate.

  • file_name (str) – File name to save the examples.

  • simple (bool) – Whether to generate simple examples.

Returns:

List of example data or None if saved to file.

Return type:

list or None

test()[source]

Get test examples.

Returns:

List of test examples.

Return type:

list

class ersilia.io.input.GenericInputAdapter(model_id=None, input_type=None, input_shape=None, config_json=None)[source]

Bases: object

Class to adapt generic inputs to a standard format.

This class uses the _GenericAdapter to handle different types of inputs and convert them into a standard format that can be processed in batches or one by one.

Parameters:
  • model_id (str, optional) – Model identifier.

  • input_type (str, optional) – Input type.

  • input_shape (str, optional) – Input shape.

  • config_json (dict, optional) – Configuration JSON.

adapt(inp, batch_size)[source]

Adapt the input data in batches.

Parameters:
  • inp (any) – The input data.

  • batch_size (int) – Size of each batch.

Yields:

list – List of adapted data in batches.

adapt_one_by_one(inp)[source]

Adapt the input data one by one.

Parameters:

inp (any) – The input data.

Yields:

dict – Adapted data.

batch_iter(data, batch_size)[source]

Yield batches of data.

Parameters:
  • data (iterable) – The data to be batched.

  • batch_size (int) – The size of each batch.

Yields:

iterable – A batch of data.

ersilia.io.output module

class ersilia.io.output.DataFrame(data: list, columns: list)[source]

Bases: object

A class used to represent a DataFrame.

data

The data of the DataFrame.

Type:

list

columns

The column names of the DataFrame.

Type:

list

decompose()[source]

Decomposes the DataFrame into its components.

write_hdf5(file_name)[source]

Writes the DataFrame to an HDF5 file.

write_text(file_name, delimiter=None)[source]

Writes the DataFrame to a text file.

write(file_name, delimiter=None)[source]

Writes the DataFrame to a file, determining the format based on the file extension.

decompose() dict[source]

Decomposes the DataFrame into its components.

Returns:

A dictionary containing keys, inputs, features, and values.

Return type:

dict

write(file_name: str, delimiter: str | None = None)[source]

Writes the DataFrame to a file, determining the format based on the file extension.

Parameters:
  • file_name (str) – The name of the file to write to.

  • delimiter (str, optional) – The delimiter to use in the text file (default is None).

write_hdf5(file_name: str)[source]

Writes the DataFrame to an HDF5 file.

Parameters:

file_name (str) – The name of the file to write to.

write_text(file_name: str, delimiter: str | None = None)[source]

Writes the DataFrame to a text file.

Parameters:
  • file_name (str) – The name of the file to write to.

  • delimiter (str, optional) – The delimiter to use in the text file (default is None).

class ersilia.io.output.DictlistDataframeConverter(config_json: dict)[source]

Bases: GenericOutputAdapter

A class used to convert between dictlist and DataFrame.

config_json

Configuration settings in JSON format.

Type:

dict

dictlist2dataframe(dl, model_id, api_name)[source]

Converts a dictlist to a DataFrame.

dataframe2dictlist(df, model_id, api_name)[source]

Converts a DataFrame to a dictlist.

dataframe2dictlist(df: DataFrame, model_id: str, api_name: str) list[source]

Converts a DataFrame to a dictlist.

Parameters:
  • df (DataFrame) – The DataFrame to convert.

  • model_id (str) – The model identifier.

  • api_name (str) – The API name.

Returns:

The converted dictlist.

Return type:

list

dictlist2dataframe(dl: dict, model_id: str, api_name: str) Dataframe[source]

Converts a dictlist to a DataFrame.

Parameters:
  • dl (dict) – The dictlist to convert.

  • model_id (str) – The model identifier.

  • api_name (str) – The API name.

Returns:

The converted DataFrame.

Return type:

Dataframe

class ersilia.io.output.GenericOutputAdapter(model_id: str | None = None, config_json: dict | None = None)[source]

Bases: ResponseRefactor

A class used to adapt generic outputs.

model_id

The model identifier.

Type:

str

config_json

Configuration settings in JSON format.

Type:

dict

adapt(result, output, model_id=None, api_name=None)[source]

Adapts the output based on the result and model.

adapt(result: str, output: str, model_id: str | None = None, api_name: str | None = None) dict[source]

Adapts the output based on the result and model.

Parameters:
  • result (str) – The result to adapt, stringyfied JSON.

  • output (str) – The output file name.

  • model_id (str, optional) – The model identifier (default is None).

  • api_name (str, optional) – The API name (default is None).

Returns:

The adapted result.

Return type:

dict

merge(subfiles: list, output_file: str)[source]

Merges the subfiles into a single output file.

Parameters:
  • subfiles (list) – The list of subfiles to merge.

  • output_file (str) – The name of the output file.

meta() dict[source]

Gets the meta information.

Returns:

The meta information.

Return type:

dict

class ersilia.io.output.ResponseRefactor(config_json: dict)[source]

Bases: ErsiliaBase

A class used to refactor API responses.

config_json

Configuration settings in JSON format.

Type:

dict

refactor_response(result)[source]

Refactors the API response.

refactor_response(result: dict) dict[source]

Refactors the API response.

Parameters:

result (dict) – The API response to refactor.

Returns:

The refactored API response.

Return type:

dict

class ersilia.io.output.TabularOutputStacker(file_names: list)[source]

Bases: object

A class used to stack tabular outputs.

file_names

The list of file names to stack.

Type:

list

stack(output)[source]

Stacks the files into a single output file.

stack(output: str)[source]

Stacks the files into a single output file.

Parameters:

output (str) – The name of the output file.

stack_hdf5(output: str)[source]

Stacks HDF5 files into a single output file.

Parameters:

output (str) – The name of the output file.

stack_text(output: str)[source]

Stacks text files into a single output file.

Parameters:

output (str) – The name of the output file.

ersilia.io.output_logger module

class ersilia.io.output_logger.TabularResultLogger[source]

Bases: object

Class to log tabular results.

This class handles logging of results from tabular files such as CSV and TSV.

Parameters:

None

tabulate(result, identifier=None, model_id=None)[source]

Tabulate the results from a file.

Parameters:
  • result (str) – Path to the result file.

  • identifier (str, optional) – Identifier to include in the results.

  • model_id (str, optional) – Model ID to include in the results.

Returns:

List of tabulated results or None if the file is not tabular.

Return type:

list or None

ersilia.io.pure module

class ersilia.io.pure.PureDataTyper(data: any, model_id: str | None = None, config_json: str | None = None)[source]

Bases: ErsiliaBase

A class used to determine the type of data provided.

Parameters:
  • data (any) – The data to be typed.

  • model_id (str, optional) – The model identifier, by default None.

  • config_json (str, optional) – Path to the configuration JSON file, by default None.

Examples

>>> data_typer = PureDataTyper(data=[1, 2, 3])
>>> data_typer.get_type()
{'type': 'numeric_array', 'shape': (3,)}
get_type() dict[source]

Determine the type of the data.

Returns:

A dictionary containing the type and shape of the data.

Return type:

dict

get_type_from_metadata() dict[source]

Get the type of data from the model metadata.

Returns:

A dictionary containing the type and shape of the data if available, otherwise None.

Return type:

dict

ersilia.io.shape module

class ersilia.io.shape.InputShape(input_shape: str | None = None)[source]

Bases: object

A class used to determine the input shape.

Parameters:

input_shape (str or None) – The input shape type. Can be ‘single’, ‘list’, or ‘pair of lists’. If None, defaults to ‘Single’.

Examples

>>> shape = InputShape("list")
>>> shape.get().name
'List'
get()[source]

Get the input shape object.

Returns:

The input shape object.

Return type:

object

class ersilia.io.shape.InputShapeList[source]

Bases: object

A class representing a list input shape.

class ersilia.io.shape.InputShapePairOfLists[source]

Bases: object

A class representing a pair of lists input shape.

class ersilia.io.shape.InputShapeSingle[source]

Bases: object

A class representing a single input shape.

Module contents