-
Notifications
You must be signed in to change notification settings - Fork 271
Implement the join_inputs_design into the current SDA workflows.
#3634
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 14 commits
8276e71
05f82da
884a69d
f7f7736
447b08d
92cd3f1
f2a96d1
40701fe
4893c11
f6d473a
f787a17
c82acac
f6f2232
a30c9e8
74d5a1e
70cfcb1
1f87740
8b0a640
fe6bdca
660186b
dd0ee2e
5ddcaa7
ea8332a
5cb5a38
fdacd5f
abecd42
fa18299
81f035b
3fc6907
6fba821
02ca610
3575463
bebf893
1409564
870593f
10310bc
300a900
408a390
5b3cc63
393c16e
4ac6250
50c2324
993e98b
78e4702
d6d06f3
460e0ee
6025d83
85c59fe
ec38802
f1d10a1
77bda48
9c3fd8e
e6ef100
087f18a
5a04563
7ba598e
19db026
2f14acc
caefddf
6da0cd6
cb2379a
668c4b1
e543c23
a44399d
4701b41
2754b91
459c945
0e08b79
af5c081
300dfae
c8a8206
441f732
9099aa0
986930b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -211,7 +211,6 @@ get.ensemble.samples <- function( ensemble.size, pft.samples, env.samples, | |
| ##' @param clean remove old output first? | ||
| ##' @param write.to.db logical: Record this run in BETY? | ||
| ##' @param restart In case this is a continuation of an old simulation. restart needs to be a list with name tags of runid, inputs, new.params (parameters), new.state (initial condition), ensemble.id (ensemble id), start.time and stop.time.See Details. | ||
| ##' @param samples Sampled inputs such as met and parameter files | ||
| ##' @param rename Decide if we want to rename previous output files, for example convert from sipnet.out to sipnet.2020-07-16.out. | ||
| ##' | ||
| ##' @return list, containing $runs = data frame of runids, $ensemble.id = the ensemble ID for these runs and $samples with ids and samples used for each tag. Also writes sensitivity analysis configuration files as a side effect | ||
|
|
@@ -226,7 +225,7 @@ get.ensemble.samples <- function( ensemble.size, pft.samples, env.samples, | |
| ##' @export | ||
| ##' @author David LeBauer, Carl Davidson, Hamze Dokoohaki | ||
| write.ensemble.configs <- function(input_design , ensemble.size, defaults, ensemble.samples, settings, model, | ||
| clean = FALSE, write.to.db = TRUE, restart = NULL, samples = NULL, rename = FALSE) { | ||
| clean = FALSE, write.to.db = TRUE, restart = NULL, rename = FALSE) { | ||
|
|
||
|
|
||
| # Check if there are NO inputs | ||
|
|
@@ -320,22 +319,18 @@ for (input_tag in names(settings$run$inputs)) { | |
| } | ||
| #now looking into the xml | ||
| samp <- settings$ensemble$samplingspace | ||
| if(is.null(samples)){ | ||
| #performing the sampling | ||
| samples <- list() | ||
| input_tags <- names(settings$run$inputs) | ||
|
|
||
| for (input_tag in input_tags) { | ||
| if (input_tag %in% colnames(input_design)) { | ||
| input_paths <- settings$run$inputs[[input_tag]]$path | ||
| input_indices <- input_design[[input_tag]] | ||
|
|
||
| samples[[input_tag]] <- list( | ||
| samples = lapply(input_indices, function(idx) input_paths[[idx]]) | ||
| ) | ||
| } | ||
|
|
||
| } | ||
| #performing the sampling | ||
| samples <- list() | ||
| input_tags <- names(settings$run$inputs) | ||
| for (input_tag in input_tags) { | ||
| if (input_tag %in% colnames(input_design)) { | ||
| input_paths <- settings$run$inputs[[input_tag]]$path | ||
| input_indices <- input_design[[input_tag]] | ||
|
|
||
| samples[[input_tag]] <- list( | ||
| samples = lapply(input_indices, function(idx) input_paths[[idx]]) | ||
| ) | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the |
||
| } | ||
| # if there is a tag required by the model but it is not specified in the xml then I replicate n times the first element | ||
| required_tags%>% | ||
|
|
@@ -515,6 +510,8 @@ for (input_tag in names(settings$run$inputs)) { | |
| for (i in seq_len(ensemble.size)) { | ||
| input_list <- list() | ||
| for (input_tag in names(inputs)) { | ||
| # if it's the parameter list, skip. | ||
| if (input_tag == "parameters") next | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make sure we are not sending parameters for the paths, as the new |
||
| if (!is.null(inputs[[input_tag]]$samples[[i]])) | ||
| input_list[[input_tag]] <- list(path = inputs[[input_tag]]$samples[[i]]) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,19 +4,20 @@ | |
| #' are shared across sites to ensure consistent parameter sampling. | ||
| #' | ||
| #' @param settings A PEcAn settings object containing ensemble configuration | ||
| #' @param sobol for activating sobol | ||
| #' @param ensemble_size Integer specifying the number of ensemble members | ||
| #' @param ensemble_samples list of ensemble parameters across PFTs. The default is NULL. | ||
| #' @param sobol for activating sobol | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add the |
||
| #' @return A list containing ensemble samples and indices | ||
| #' | ||
| #' @export | ||
|
|
||
| generate_joint_ensemble_design <- function(settings, | ||
| ensemble_size, | ||
| ensemble_samples = NULL, | ||
| sobol = FALSE) { | ||
| if (sobol) { | ||
| ensemble_size <- as.numeric(ensemble_size) * 2 | ||
| } | ||
|
|
||
| ens.sample.method <- settings$ensemble$samplingspace$parameters$method | ||
| design_list <- list() | ||
| sampled_inputs <- list() | ||
|
|
@@ -51,29 +52,34 @@ generate_joint_ensemble_design <- function(settings, | |
| sampled_inputs[[input_tag]] <- input_result$ids | ||
| design_list[[input_tag]] <- input_result$ids | ||
| } | ||
|
|
||
| # Sample parameters | ||
| PEcAn.uncertainty::get.parameter.samples( | ||
| settings, | ||
| ensemble.size = ensemble_size, | ||
| posterior.files, | ||
| ens.sample.method | ||
| ) | ||
|
|
||
|
|
||
| # Sample parameters if we don't have it. | ||
| if (is.null(ensemble_samples)) { | ||
| PEcAn.uncertainty::get.parameter.samples( | ||
| settings, | ||
| ensemble.size = ensemble_size, | ||
| posterior.files, | ||
| ens.sample.method | ||
| ) | ||
| samples.file <- file.path(settings$outdir, "samples.Rdata") | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you clarify the argument for when it makes sense to assume that we have ensemble_samples already? In other words, in what cases would you want/need to recycle a previous ensemble_samples rather than generate a new sample from the posteriors? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
|
||
| # Load samples from file | ||
| samples.file <- file.path(settings$outdir, "samples.Rdata") | ||
| samples <- new.env() | ||
| if (file.exists(samples.file)) { | ||
| load(samples.file, envir = samples) | ||
| if (!is.null(samples$ensemble.samples)) { | ||
| # Just a placeholder: extract representative trait index per ensemble member | ||
| # You may want to flatten or select indices per trait | ||
| design_list[["param"]] <- seq_len(ensemble_size) | ||
| # if we don't have the parameters from the outside. | ||
| if (is.null(ensemble_samples)) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why have to consecutive if(is.null(ensemble_samples) blocks? why can't these be combined into one block? |
||
| if (ile.exists(samples.file)) { | ||
| load(samples.file, envir = samples) | ||
| } else { | ||
| PEcAn.logger::logger.warn("ensemble.samples not found in samples.Rdata") | ||
| PEcAn.logger::logger.error(samples.file, "not found, this file is required") | ||
| } | ||
| } | ||
| if (!is.null(samples$ensemble.samples) | !is.null(ensemble_samples)) { | ||
| # Just a placeholder: extract representative trait index per ensemble member | ||
| # You may want to flatten or select indices per trait | ||
| design_list[["param"]] <- seq_len(ensemble_size) | ||
| } else { | ||
| PEcAn.logger::logger.error(samples.file, "not found, this file is required") | ||
| PEcAn.logger::logger.warn("ensemble.samples not found in samples.Rdata") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why drop this from error to warn? |
||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add |
||
| design_matrix <- data.frame(design_list) | ||
|
|
||
|
|
@@ -85,7 +91,5 @@ generate_joint_ensemble_design <- function(settings, | |
| return(sobol_obj) | ||
| } | ||
|
|
||
|
|
||
|
|
||
| return(list(X = design_matrix)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it important that this be a list? All the uses I've seen so far immediately subset the result to only store the X component, so would it make sense to return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is important so that the sobol version works correctly. This ensures that regardless of whether the sobol or non-sobol version is called that the output is a list that includes the design as X. In the sobol version the list includes additional info beyond just X that's required by the function that does the sobol index calculations, but not required to do the runs themselves There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 Can you add this to the function docs, please? I think it'd be enough to list in the @return block the possible items for the Sobol case and mention that in the non-sobol case the list only contains X |
||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the
samplesargument as it is no longer needed.