ersilia.io package¶
Subpackages¶
- ersilia.io.readers package
- ersilia.io.types package
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”).
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.
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:
- 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
- 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.
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
- 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).
- 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
- 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
- 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
- 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: str)[source]¶
Stacks the 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,)}
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'
- class ersilia.io.shape.InputShapeList[source]¶
Bases:
object
A class representing a list input shape.