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:
objectClass 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:
objectClass 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:
ErsiliaBaseBase 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:
ErsiliaBaseClass to generate examples for a model.
- Parameters:
model_id (str) – Model identifier.
config_json (dict, optional) – Configuration JSON.
- check_model_id(model_id)[source]¶
Check if the model ID is valid.
- Parameters:
model_id (str) – Model identifier.
- Return type:
None
- Raises:
NullModelIdentifierError – If the model ID is None.
- example(n_samples, file_name, mode)[source]¶
Generate example data.
- Parameters:
n_samples (int) – Number of samples to generate.
file_name (str) – File name to save the examples.
mode (str) – Mode for generating examples: “random”, “deterministic”, or “curated” (the model’s own example inputs; “predefined” is accepted as an alias).
- Returns:
List of example data or file content if saved to file.
- Return type:
list or str
- fixed_example(n_samples, file_name)[source]¶
Generate deterministic example data. Samples same types of examples for each any sampling.
- Parameters:
n_samples (int) – Number of samples to generate.
file_name (str) – File name to save the examples.
- Return type:
None
- 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
- class ersilia.io.input.GenericInputAdapter(model_id=None, input_type=None, input_shape=None, config_json=None)[source]¶
Bases:
objectClass 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, dtype: any, dim: int)[source]¶
Bases:
objectA class used to represent a DataFrame.
- data¶
The data of the DataFrame.
- Type:
list
- columns¶
The column names of the DataFrame.
- Type:
list
- dtype¶
Data type for the output part of the data
- Type:
any
- dim¶
The number of dimensions of the data.
- Type:
int
- 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, append: bool = False, check_unprocessable: bool = True)[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).
append (bool, optional) – If True, append rows to a file previously written by this method.
check_unprocessable (bool, optional) – If True, raise when the data is a single unprocessable input. Disable when writing one chunk of a larger output.
- write_hdf5(file_name: str, append: bool = False)[source]¶
Writes the DataFrame to an HDF5 file.
- Parameters:
file_name (str) – The name of the file to write to.
append (bool, optional) – If True, append rows to an existing file written by this method.
- write_text(file_name: str, delimiter: str = None, chunksize: int = 50000, append: bool = False)[source]¶
Writes the DataFrame to a text file, wrapping any string-valued field in quotes, except for the first and second columns, which are never quoted. If append is True, rows are appended to an existing file without a header.
- class ersilia.io.output.DictlistDataframeConverter(config_json: dict)[source]¶
Bases:
GenericOutputAdapterA 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, columns_info: dict = None, config_json: dict = None)[source]¶
Bases:
ResponseRefactorA 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, api_name: str = 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.
- write_batch(inputs: list, results: list, output: str, append: bool)[source]¶
Writes one batch of merged API results to a CSV, TSV or HDF5 file.
Produces the same file as standardizing the batch and calling write_chunk, but builds the rows in one pass and converts float outputs as a single matrix instead of cell by cell.
- Parameters:
inputs (list) – Input records ({“key”: …, “input”: …}), one per result.
results (list) – One dict per input: the input first, then the output values in column order.
output (str) – The output file name.
append (bool) – If True, append to the file written by a previous batch.
- write_chunk(result: list, output: str, append: bool)[source]¶
Writes one chunk of standardized results to a CSV, TSV or HDF5 file.
Used to stream large runs to disk batch by batch instead of holding the full output in memory.
- Parameters:
result (list) – Standardized results ({“input”: …, “output”: …} dicts).
output (str) – The output file name.
append (bool) – If True, append to the file written by a previous chunk.
- class ersilia.io.output.ResponseRefactor(config_json: dict)[source]¶
Bases:
ErsiliaBaseA 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:
objectA 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¶
ersilia.io.pure module¶
- class ersilia.io.pure.PureDataTyper(data: any, model_id: str = None, config_json: str = None)[source]¶
Bases:
ErsiliaBaseA 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)[source]¶
Bases:
objectA class used to determine the input shape.
- Parameters:
input_shape (str or None) – The input shape type. Can only be ‘single’. If None, defaults to ‘Single’.
Examples
>>> shape = InputShape("list") >>> shape.get().name 'List'