Skip to content

Commit

Permalink
PEtabSelect: Save/Load global pets struct
Browse files Browse the repository at this point in the history
By saving the global struct "pets", the history and state of model selection is not lost when the model selection terminates
The pets struct can be recovered by calling arPetsLoad
  • Loading branch information
niklasneubrand committed Jan 23, 2025
1 parent caf4fbf commit 16d4e3c
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
29 changes: 29 additions & 0 deletions arFramework3/PEtabSelect/arPetsLoad.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
function arPetsLoad(name, PetsOutputDir)
% ARPETSLOAD loads the PEtab Select struct "pets" from file.
%
% The python module petab_select cannot be saved to/loaded from a .mat file
% Therefore, only the relevant fields are saved and loaded.
%
% INPUT:
% name: Name of the file to load the struct from.
% PetsOutputDir: Directory to load the file from.
%
% SEE: arPetsSave

arguments
name char = 'petsSave';
PetsOutputDir char = fullfile(pwd(), 'PEtabSelect', 'Results');
end

% initialize new pets struct
arPetsInitModule;

% load the struct from file
loadPath = fullfile(PetsOutputDir, name);
load(loadPath, "petsSave");

% assign the filed to the global variable
pets.history = petsSave.history;
pets.problem = petsSave.problem;

end
30 changes: 30 additions & 0 deletions arFramework3/PEtabSelect/arPetsSave.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
function arPetsSave(name, PetsOutputDir)
% ARPETSSAVE saves the PEtab Select struct "pets" to file.
%
% The python module petab_select cannot be saved to/loaded from a .mat file
% Therefore, only the relevant fields are saved and loaded.
%
% INPUT:
% name: Name of the file to save the struct to.
% PetsOutputDir: Directory to save the file to.
%
% SEE: arPetsLoad

arguments
name char = 'petsSave';
PetsOutputDir char = fullfile(pwd(), 'PEtabSelect', 'Results');
end

% access the global pets struct
global pets

% create a struct with the relevant fields
petsSave = struct();
petsSave.history = pets.history;
petsSave.problem = pets.problem;

% save the struct to file
savePath = fullfile(PetsOutputDir, name);
save(savePath, "petsSave")

end
3 changes: 3 additions & 0 deletions arFramework3/PEtabSelect/arPetsSelectModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ function arPetsSelectModel(PetsProblemFile, options)
% create output directory
[~] = mkdir(options.PetsOutputDir);

% save the PEtab Select struct to file
arPetsSave('petsSave', options.PetsOutputDir);

% get the overall best model and save it to yaml file
final_model = get_best(pets.problem, pets.problem.state.models);
final_model.to_yaml(fullfile(options.PetsOutputDir, 'selected_model.yaml'));
Expand Down

0 comments on commit 16d4e3c

Please sign in to comment.