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

Fix simulation id validation #138

Merged
merged 6 commits into from
Jul 4, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions R/utilities-simulation.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,30 @@
#' the mismatch or absence of IDs.
#' @keywords internal
.validateSimulationIds <- function(simulationIds, piParameters, outputMappings) {
# Extract unique IDs from piParameters
piParamIds <- lapply(piParameters, function(param) .getSimulationContainer(param$parameters[[1]])$id)
# Extract unique IDs from piParameters assuming up to two levels of list depth
piParamIds <- lapply(piParameters, function(param) {
if (is.list(param$parameters)) {
return(lapply(param$parameters, function(sub_param) {
.getSimulationContainer(sub_param)$id
}))
} else {
return(.getSimulationContainer(param$parameters[[1]])$id)
}
})
piParamIds <- unique(unlist(piParamIds))

# Extract unique IDs from outputMappings
outputMappingIds <- lapply(outputMappings, function(mapping) .getSimulationContainer(mapping$quantity)$id)
outputMappingIds <- unique(unlist(outputMappingIds))

# Validate that each simulationId is present in both piParamIds and outputMappingIds
for (id in simulationIds) {
if (!(id %in% piParamIds && id %in% outputMappingIds)) {
stop(messages$errorSimulationIdMissing(id))
}
# sort IDs before comparison
simulationIds <- sort(unique(unlist(simulationIds)))
piParamIds <- sort(piParamIds)
outputMappingIds <- sort(outputMappingIds)

# Validate that simulationId is idnetical with piParamIds and outputMappingIds

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Validate that simulationId is idnetical with piParamIds and outputMappingIds
# Validate that simulationId is identical with piParamIds and outputMappingIds

if (!identical(simulationIds, piParamIds) || !identical(simulationIds, outputMappingIds)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When could this happen? How could the user invoke this behavior? @rengelke

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the user forget data or parameters or simulations in the ParameterIdentification$new(), for example.
cf added tests

stop(messages$errorSimulationIdMissing(id))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The id is not defined here anymore

}

return()
Expand Down
Loading