Variable saving and loading
Saving variables into a JSON file
Saves all module variables to a .variables.json
file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filepath
|
str | Path
|
|
required |
overwrite
|
bool
|
Whether we should overwrite any existing program at the target location, or instead ask the user via an interactive prompt. |
True
|
Source code in synalinks/src/programs/program.py
Saving variables into JSON dict
Retrieves tree-like structure of program variables.
This method allows retrieval of different program variables (trainable, non-trainable, optimizer, and metrics). The variables are returned in a nested dictionary format, where the keys correspond to the variable names and the values are the nested representations of the variables.
Example:
program.compile(
optimizer=synalinks.optimizers.RandomFewShot(),
reward=synalinks.rewards.ExactMatch(),
)
program.fit(x=x_train, y=y_train)
state_tree = program.get_state_tree()
Returns:
Type | Description |
---|---|
dict
|
A dictionary containing the nested representations of the requested variables. The keys are the variable names, and the values are the corresponding nested dictionaries. |
Source code in synalinks/src/programs/program.py
Loading variables from a JSON file
Load all module variables from a .variable.json
file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filepath
|
str | Path
|
|
required |
Source code in synalinks/src/programs/program.py
Load variables from a JSON dict
Assigns values to variables of the program.
This method takes a dictionary of nested variable values, which
represents the state tree of the program, and assigns them to the
corresponding variables of the program. The dictionary keys represent the
variable names (e.g., 'trainable_variables'
, 'optimizer_variables'
),
and the values are nested dictionaries containing the variable
paths and their corresponding values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state_tree
|
dict
|
A dictionary representing the state tree of the program. The keys are the variable names, and the values are nested dictionaries representing the variable paths and their values. |
required |