1414# ' @param overwrite logical: Replace config files if they already exist?
1515# ' @param input_design Optional. The parameter/input design for the runs,
1616# ' normally the full result of \code{generate_joint_ensemble_design()}: a list
17- # ' with \code{X } (a data.frame whose \code{param} column selects rows of
17+ # ' with \code{design_matrix } (a data.frame whose \code{param} column selects rows of
1818# ' \code{trait.samples}/\code{ensemble.samples}, plus optional columns named
1919# ' for \code{settings$run$inputs} tags such as \code{met} or \code{soil}) and
2020# ' \code{samples} (the parameter bundle those indices point into). Can be:
2121# ' \itemize{
22- # ' \item The \code{list(X , samples)} returned by
22+ # ' \item The \code{list(design_matrix , samples)} returned by
2323# ' \code{generate_joint_ensemble_design()}
2424# ' \item \code{NULL} to generate the design and samples internally from
2525# ' \code{settings}
@@ -161,9 +161,10 @@ runModule.run.write.configs <- function(settings,
161161# ' \item If \code{input_design} is already a list with
162162# ' \code{ensemble}/\code{sensitivity} keys (e.g. threaded from a
163163# ' MultiSettings parent), return as-is.
164- # ' \item If \code{input_design} is the \code{list(X, samples)} from
165- # ' \code{generate_joint_ensemble_design()}, use \code{X} as the ensemble
166- # ' design and \code{samples} as the bundle (no resampling).
164+ # ' \item If \code{input_design} is the \code{list(design_matrix, samples)}
165+ # ' from \code{generate_joint_ensemble_design()}, use the design matrix
166+ # ' as the ensemble design and \code{samples} as the bundle (no
167+ # ' resampling). \code{X} is accepted as the older name for it.
167168# ' \item If \code{input_design} is a bare data.frame (a design without its
168169# ' samples), raise an error: the design's \code{param} indices only match
169170# ' the samples they were drawn with.
@@ -191,24 +192,32 @@ runModule.run.write.configs <- function(settings,
191192 # into the samples it was drawn with, so a design must arrive together with
192193 # those samples; otherwise it would be silently paired with a fresh, mismatched
193194 # resample. We therefore accept the full generate_joint_ensemble_design()
194- # result (a list with X and samples) and reject a bare design.
195+ # result (a list with design_matrix and samples) and reject a bare design.
195196 if (! is.null(input_design )) {
196- if (is.list(input_design ) && ! is.data.frame(input_design ) &&
197- all(c(" X" , " samples" ) %in% names(input_design )) &&
198- ! is.null(input_design $ samples )) {
199- designs $ ensemble <- input_design $ X
197+ # Generators return the design as `design_matrix`. `X` is the older name for
198+ # the same matrix, kept so existing callers keep working, and is what
199+ # sensitivity sets on a sobol object.
200+ supplied_design <- if (is.list(input_design ) && ! is.data.frame(input_design )) {
201+ input_design [[" design_matrix" ]] %|| % input_design [[" X" ]]
202+ } else {
203+ NULL
204+ }
205+
206+ if (! is.null(supplied_design ) && ! is.null(input_design $ samples )) {
207+ designs $ ensemble <- supplied_design
200208 supplied_samples <- input_design $ samples
201209 } else if (is.data.frame(input_design )) {
202210 PEcAn.logger :: logger.severe(
203211 " input_design was supplied without its parameter samples." ,
204212 " Pass the full generate_joint_ensemble_design() result" ,
205- " (a list with `X` and `samples`) so the design's `param` indices match" ,
206- " the samples, or leave input_design = NULL to generate both together."
213+ " (a list with `design_matrix` and `samples`) so the design's `param`" ,
214+ " indices match the samples, or leave input_design = NULL to generate" ,
215+ " both together."
207216 )
208217 } else {
209218 PEcAn.logger :: logger.severe(
210- " Unrecognized input_design format. Expected NULL or the list(X, samples) " ,
211- " returned by generate_joint_ensemble_design()."
219+ " Unrecognized input_design format. Expected NULL or the" ,
220+ " list(design_matrix, samples) returned by generate_joint_ensemble_design()."
212221 )
213222 }
214223 }
@@ -252,6 +261,20 @@ runModule.run.write.configs <- function(settings,
252261 designs $ samples <- samples
253262 }
254263
264+ # Deprecation: internal design generation is going away. Passing input_design
265+ # explicitly (the generate_joint_ensemble_design() result) will become the
266+ # required path. Warn only when we are actually about to auto-generate.
267+ auto_generating <-
268+ (is.null(designs $ ensemble ) && need_ensemble ) ||
269+ (is.null(designs $ sensitivity ) && need_sa )
270+ if (auto_generating ) {
271+ PEcAn.logger :: logger.warn(
272+ " Internal input design generation is deprecated and will be removed." ,
273+ " Pass input_design explicitly as the list(design_matrix, samples) returned" ,
274+ " by generate_joint_ensemble_design(); this will become required."
275+ )
276+ }
277+
255278 # Generate the ensemble design only when the caller did not supply one,
256279 # handing over the resolved samples so the generator does not resample.
257280 if (is.null(designs $ ensemble ) && need_ensemble ) {
@@ -260,17 +283,17 @@ runModule.run.write.configs <- function(settings,
260283 ensemble_size = ensemble_size ,
261284 samples = designs $ samples
262285 )
263- designs $ ensemble <- design_result $ X
286+ designs $ ensemble <- design_result $ design_matrix % || % design_result $ X
264287 }
265288
266289 # Generate the SA design if needed, threading the SA samples so the generator
267290 # uses them directly instead of re-reading samples.Rdata via the deprecated path.
268291 if (is.null(designs $ sensitivity ) && need_sa ) {
269292 design_result <- PEcAn.uncertainty :: generate_OAT_SA_design(
270293 settings ,
271- sa_samples = designs $ samples $ sa. samples
294+ samples = designs $ samples
272295 )
273- designs $ sensitivity <- design_result $ X
296+ designs $ sensitivity <- design_result $ design_matrix % || % design_result $ X
274297 }
275298
276299 return (designs )
0 commit comments