Neps state
The main state object that holds all the shared state objects.
This object is used to interact with the shared state objects in a safe atomic manner, such that each worker can create an identical NePSState and interact with it without having to worry about locking or out-dated information.
For an actual instantiation of this object, see
create_or_load_filebased_neps_state().
NePSState
dataclass
#
NePSState(
path: Path,
_trial_lock: FileLocker,
_trial_repo: TrialRepo,
_optimizer_lock: FileLocker,
_optimizer_info_path: Path,
_optimizer_info: OptimizerInfo,
_optimizer_state_path: Path,
_optimizer_state: OptimizationState,
_pipeline_space_path: Path,
_err_lock: FileLocker,
_shared_errors_path: Path,
_shared_errors: ErrDump,
_pipeline_space: (
SearchSpace | PipelineSpace | None
) = None,
)
The main state object that holds all the shared state objects.
__eq__
#
Compare two NePSState objects for equality.
Pipeline spaces are compared by pickle dumps to handle cases where the class type differs after unpickling but the content is equivalent.
Source code in neps\state\neps_state.py
all_trial_ids
#
create_or_load
classmethod
#
create_or_load(
path: Path,
*,
load_only: bool = False,
optimizer_info: OptimizerInfo | None = None,
optimizer_state: OptimizationState | None = None,
pipeline_space: (
SearchSpace | PipelineSpace | None
) = None
) -> NePSState
Create a new NePSState in a directory or load the existing one if it already exists, depending on the argument.
Warning
We check that the optimizer info in the NePSState on disk matches the one that is passed. However we do not lock this check so it is possible that if two processes try to create a NePSState at the same time, both with different optimizer infos, that one will fail to create the NePSState. This is a limitation of the current design.
In principal, we could allow multiple optimizers to be run and share the same set of trials.
We do the same check for the pipeline space, if provided.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
The directory to create the state in.
TYPE:
|
load_only
|
If True, only load the state and do not create a new one.
TYPE:
|
optimizer_info
|
The optimizer info to use.
TYPE:
|
optimizer_state
|
The optimizer state to use.
TYPE:
|
pipeline_space
|
The pipeline space to save. Optional - if provided, it will be saved to disk and validated on subsequent loads.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NePSState
|
The NePSState. |
| RAISES | DESCRIPTION |
|---|---|
NePSError
|
If the optimizer info on disk does not match the one provided, or if the pipeline space on disk does not match the one provided. |
FileNotFoundError
|
If load_only=True and no NePSState exists at the path. |
Source code in neps\state\neps_state.py
698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 | |
lock_and_get_current_evaluating_trials
#
Get the current evaluating trials.
Source code in neps\state\neps_state.py
lock_and_get_errors
#
lock_and_get_errors() -> ErrDump
Get all the errors that have occurred during the optimization.
lock_and_get_next_pending_trial
#
lock_and_get_next_pending_trial() -> Trial | None
Get the next pending trial.
Source code in neps\state\neps_state.py
lock_and_get_optimizer_info
#
lock_and_get_optimizer_info() -> OptimizerInfo
lock_and_get_optimizer_state
#
lock_and_get_optimizer_state() -> OptimizationState
Get the optimizer state.
Source code in neps\state\neps_state.py
lock_and_get_search_space
#
lock_and_get_search_space() -> (
SearchSpace | PipelineSpace | None
)
Get the pipeline space, with the lock acquired.
| RETURNS | DESCRIPTION |
|---|---|
SearchSpace | PipelineSpace | None
|
The pipeline space if it was saved to disk, None otherwise. |
Source code in neps\state\neps_state.py
lock_and_get_trial_by_id
#
lock_and_import_trials
#
Acquire the state lock and import trials from external data.
| PARAMETER | DESCRIPTION |
|---|---|
imported_configs
|
List of trial dictionaries to import.
TYPE:
|
worker_id
|
The worker ID performing the import.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Trial | list[Trial]
|
Trial or list of Trial objects imported. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If data is not a list or trial import fails. |
NePSError
|
If storing or reporting trials fails. |
Source code in neps\state\neps_state.py
lock_and_read_trials
#
lock_and_report_trial_evaluation
#
Acquire the state lock and report the trial evaluation.
Source code in neps\state\neps_state.py
lock_and_sample_trial
#
lock_and_sample_trial(
optimizer: AskFunction,
*,
worker_id: str,
n: None = None
) -> Trial
lock_and_sample_trial(
optimizer: AskFunction, *, worker_id: str, n: int
) -> list[Trial]
lock_and_sample_trial(
optimizer: AskFunction,
*,
worker_id: str,
n: int | None = None
) -> Trial | list[Trial]
Acquire the state lock and sample a trial.
Source code in neps\state\neps_state.py
lock_and_set_new_worker_id
#
Acquire the state lock and set a new worker id in the optimizer state.
| PARAMETER | DESCRIPTION |
|---|---|
worker_id
|
The worker id to set. If
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The worker id that was set. |
| RAISES | DESCRIPTION |
|---|---|
NePSError
|
If the worker id already exists. |
Source code in neps\state\neps_state.py
put_updated_trial
#
put_updated_trial(
trial: Trial,
*,
hints: (
list[TrialWriteHint] | TrialWriteHint | None
) = None
) -> None
Update the trial.
| PARAMETER | DESCRIPTION |
|---|---|
trial
|
The trial to update.
TYPE:
|
hints
|
The hints to use when updating the trial. Defines what files need
to be updated.
If you don't know, leave
TYPE:
|
Source code in neps\state\neps_state.py
unsafe_retry_get_trial_by_id
#
Get a trial by id but use unsafe retries.
Source code in neps\state\neps_state.py
TrialRepo
dataclass
#
TrialRepo(directory: Path)
A repository for trials that are stored on disk.
Warning
This class does not implement locking and it is up to the caller to ensure there are no race conflicts.
get_valid_evaluated_trials
#
Get all trials that have a valid evaluation report.
Source code in neps\state\neps_state.py
latest
#
Get the latest trials from the cache.
Source code in neps\state\neps_state.py
list_trial_ids
#
List all the trial ids on disk.
load_trial_from_disk
#
Load a trial from disk.
| RAISES | DESCRIPTION |
|---|---|
TrialNotFoundError
|
If the trial is not found on disk. |
Source code in neps\state\neps_state.py
store_new_trial
#
Write a new trial to disk.
| RAISES | DESCRIPTION |
|---|---|
TrialAlreadyExistsError
|
If the trial already exists on disk. |
Source code in neps\state\neps_state.py
update_trial
#
update_trial(
trial: Trial,
*,
hints: (
Iterable[TrialWriteHint] | TrialWriteHint | None
) = ("report", "metadata")
) -> None
Update a trial on disk.
| PARAMETER | DESCRIPTION |
|---|---|
trial
|
The trial to update.
TYPE:
|
hints
|
The hints to use when updating the trial. Defines what files need
to be updated.
If you don't know, leave
TYPE:
|