-
Notifications
You must be signed in to change notification settings - Fork 1
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
Changes from 2 commits
5f88b54
0b484df
0aa89e5
d187875
adf5ab5
aed9afd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
if (!identical(simulationIds, piParamIds) || !identical(simulationIds, outputMappingIds)) { | ||
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. When could this happen? How could the user invoke this behavior? @rengelke 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. If the user forget data or parameters or simulations in the ParameterIdentification$new(), for example. |
||
stop(messages$errorSimulationIdMissing(id)) | ||
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. The |
||
} | ||
|
||
return() | ||
|
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.