Skip to content
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

paramCheckOtherMods can't deal with vector parameters with length > 1 #252

Open
CeresBarros opened this issue Aug 23, 2023 · 3 comments
Open

Comments

@CeresBarros
Copy link
Member

CeresBarros commented Aug 23, 2023

When p[[paramToCheck]] has vectors of length > 1 and the parameter is not defined in the current module, the following line will break this structure due to the unlist

  paramToUpdateValInOtherMods <- unlist(lapply(params, function(p) p[[paramToCheck]]))

for instance:

Browse[3]> lapply(params, function(p) p[[paramToCheck]])
$.progress
NULL

$checkpoint
NULL

$.globals
NULL

$Biomass_borealDataPrep
NULL

$Biomass_speciesParameters
NULL

$Biomass_sppEcoregDataPrep
NULL

$Biomass_sppEcoregPredict
[1] "pixelGroup"  "speciesCode" "age"        

$PermafrostThaw
NULL

$Biomass_core
[1] "pixelGroup"  "speciesCode" "age"

becomes

Browse[3]> unlist(lapply(params, function(p) p[[paramToCheck]]))
Biomass_sppEcoregPredict1 Biomass_sppEcoregPredict2 Biomass_sppEcoregPredict3             Biomass_core1             Biomass_core2 
             "pixelGroup"             "speciesCode"                     "age"              "pixelGroup"             "speciesCode" 
            Biomass_core3 
                    "age" 

The structure of the parameter must be preserved to check for parameter equality across modules

@CeresBarros
Copy link
Member Author

will try to get a reprex

@CeresBarros
Copy link
Member Author

reprex

Require::Require("PredictiveEcology/SpaDES.core@52d2258477571e6d6dc869e0f7f52b6a7c01c2b0")  ## development as of August 23rd

options(spades.moduleCodeChecks = FALSE, 
        spades.debug = FALSE,
        reproducible.ask = FALSE, 
        spades.useRequire = FALSE)

tmpdir <- file.path(tempdir())
setPaths(cachePath = file.path(tmpdir, "cache"),
         modulePath = system.file("sampleModules", package = "SpaDES.core"),
         outputPath = file.path(tmpdir, "outputs"))
pths <- getPaths()

mySim <- simInit(
  times = list(start = 0.0, end = 1.0, timeunit = "year"),
  params = list(
    .globals = list(stackName = "landscape", 
                    burnStats = "nPixelsBurned"),
    # Turn off interactive plotting
    fireSpread = list(.plotInitialTime = NA),
    caribouMovement = list(.plotInitialTime = NA,
                           .useCache = c(".inputObjects", "init")),
    randomLandscapes = list(.plotInitialTime = NA,
                            .useCache = c(".inputObjects", "init"))
  ),
  modules = list("randomLandscapes", "fireSpread", "caribouMovement"),
  paths = pths,
  # Save final state of landscape and caribou
  outputs = data.frame(objectName = c("landscape", "caribou"),
                       stringsAsFactors = FALSE)
)

spades(mySim, debug = "fireSpread")
## then in  browser mode:
paramCheckOtherMods(sim, ".useCache")
## Error in data.frame(module = currentModule, value = paramInThisMod, row.names = NULL) : 
  arguments imply differing number of rows: 1, 0

@CeresBarros
Copy link
Member Author

CeresBarros commented Aug 23, 2023

After a bit more digging, I think the issue is not only related to my initial message. But is also further downstream. The error is linked to the parameter not being defined in the current module (so paramInThisMod is NULL), there being several definitions of the parameter (definef in several modules) -- which leads failure in line 52.

But also, even in the case where there are several equal definitions of the parameter (as in the example above), the function is failing to detect that they are all the same -- in which case it should output the parameter value

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant