Loading¶
rupsycho.experiment_from_file
¶
Load one experiment from a JSON file.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
Path of the JSON file.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ExperimentDocument
|
The validated experiment. |
| RAISES | DESCRIPTION |
|---|---|
FileNotFoundError
|
If the file does not exist. |
ValueError
|
If the file is not valid JSON or not a valid experiment (pydantic's
|
rupsycho.experiment_from_dict
¶
Create one experiment from a configuration dictionary.
| PARAMETER | DESCRIPTION |
|---|---|
json_data
|
The experiment configuration (see the configuration reference).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ExperimentDocument
|
The validated experiment. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the configuration is invalid (pydantic's |
rupsycho.experiments_from_files
¶
Load all experiments matching a path or glob pattern.
| PARAMETER | DESCRIPTION |
|---|---|
path_pattern
|
A JSON file or glob pattern such as
TYPE:
|
strict
|
Raise on the first invalid file instead of logging and skipping it.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ExperimentCollection
|
A collection of the valid experiments, ordered by file name. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If no file matches the pattern. |
rupsycho.experiments_from_dicts
¶
experiments_from_dicts(json_data_list: list[dict[str, Any]], *, strict: bool = False) -> Iterator[ExperimentDocument]
Lazily create experiments from configuration dictionaries.
| PARAMETER | DESCRIPTION |
|---|---|
json_data_list
|
The experiment configurations.
TYPE:
|
strict
|
Raise on the first invalid configuration instead of logging and skipping it.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Iterator[ExperimentDocument]
|
An iterator over the valid experiments. |
rupsycho.reader.ExperimentLoader
¶
A document loader that reads JSON files validated by the ExperimentDocument model.
| PARAMETER | DESCRIPTION |
|---|---|
path_pattern
|
A file path or glob pattern (
TYPE:
|
strict
|
Raise on the first invalid experiment instead of logging and skipping it.
TYPE:
|
Example
lazy_load
¶
Lazily load and validate the experiments in the resolved files.
| PARAMETER | DESCRIPTION |
|---|---|
path_pattern
|
A glob pattern or single file path; defaults to the pattern the loader was created with.
TYPE:
|
| YIELDS | DESCRIPTION |
|---|---|
ExperimentDocument
|
One validated experiment per readable, valid file. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If no file paths are available. |
lazy_load_from_dicts
¶
Lazily validate dictionaries as experiments.
| PARAMETER | DESCRIPTION |
|---|---|
dicts
|
Experiment configurations.
TYPE:
|
| YIELDS | DESCRIPTION |
|---|---|
ExperimentDocument
|
One validated experiment per valid dictionary. |
alazy_load_from_dicts
async
¶
Asynchronous version of
lazy_load_from_dicts.
Bundled examples¶
rupsycho.datasets
¶
Bundled example experiments.
The wheel ships a ready-to-run Big Five Inventory configuration so that the documentation
examples work after a plain pip install. Larger study configurations live in the
examples/data folder of the repository.
list_examples
¶
load_example_config
¶
Load a bundled example configuration as a dictionary.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Name of the example (see
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Any]
|
A fresh dictionary that may be modified freely, for instance to swap the model. |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If there is no example with that name. |
load_example_experiment
¶
load_example_experiment(name: str = 'bfi', *, models: dict[str, Any] | None = None, seeds: list[int] | list[str] | None = None) -> ExperimentDocument
Create an experiment from a bundled example.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Name of the example (see
TYPE:
|
models
|
Replacement for the
TYPE:
|
seeds
|
Replacement for the example's seeds, e.g.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ExperimentDocument
|
The validated experiment. |
Deprecated example experiment¶
rupsycho.example_experiment_bfi
¶
example_experiment_bfi(model_name: str = 'google/flan-t5-small', pipeline_type: str = 'text2text-generation', temperature: float = 0.7, max_new_tokens: int = 128, api_key: str | None = None) -> ExperimentDocument
Create a tiny Big Five experiment around a Hugging Face pipeline.
Deprecated
Use load_example_experiment and add your
model with experiment.add_model.
| PARAMETER | DESCRIPTION |
|---|---|
model_name
|
Name of the Hugging Face model to use.
TYPE:
|
pipeline_type
|
Pipeline task, e.g.
TYPE:
|
temperature
|
Sampling temperature.
TYPE:
|
max_new_tokens
|
Maximum number of generated tokens.
TYPE:
|
api_key
|
Optional Hugging Face token for gated models.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ExperimentDocument
|
A configured experiment with the model already added. |
| RAISES | DESCRIPTION |
|---|---|
ImportError
|
If the |
Utilities¶
rupsycho.utils
¶
json_loader
¶
Load a JSON file from the given path and return its contents as a dictionary.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
Path to the JSON file.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict
|
Dictionary containing the JSON data. |
json_saver
¶
Save a dictionary as a JSON file at the specified path and file name. If no path is provided, saves to the current directory. Prints the full path upon successful save.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
Dictionary to save as JSON.
TYPE:
|
name
|
Name of the file to save. Defaults to 'output'.
TYPE:
|
path
|
Directory path where the file will be saved. Defaults to the current directory.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
None |
import_tqdm
¶
Return the tqdm flavour that fits the environment.
In a Jupyter kernel the notebook widget variant is returned, everywhere else the console progress bar. IPython is only inspected if it has already been imported, so plain scripts never pay for importing it.
| RETURNS | DESCRIPTION |
|---|---|
Any
|
The |