Skip to content

Commit

Permalink
Fix orderly prod index query
Browse files Browse the repository at this point in the history
  • Loading branch information
CosmoNaught committed Aug 14, 2024
1 parent acbda01 commit 301f8d2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 23 deletions.
23 changes: 11 additions & 12 deletions R/orderly_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,48 +25,47 @@ check_parameter_set <- function(i) {

#' Execute Parameter Set Checks
#'
#' This function executes the `check_parameter_set` function for a range of parameter sets, either sequentially or in parallel.
#' This function executes the `check_parameter_set` function for a vector of parameter sets, either sequentially or in parallel.
#'
#' @param start The starting index of the parameter sets to check.
#' @param end The ending index of the parameter sets to check.
#' @param indices A vector of indices of the parameter sets to check.
#' @param parallel Logical. If `TRUE`, the checks are run in parallel using multiple cores; otherwise, they are run sequentially.
#'
#' @return A list of results for each parameter set, including success flags and any errors.
#'
#' @keywords internal
#' @export
execute_checks <- function(start, end, parallel) {
execute_checks <- function(indices, parallel) {
if (parallel) {
num_cores <- parallel::detectCores() - 1 # Use all but one core
cl <- parallel::makeCluster(num_cores)
on.exit(parallel::stopCluster(cl), add = TRUE) # Ensure the cluster is stopped even if there's an error
results <- parallel::parLapply(cl, start:end, check_parameter_set)
results <- parallel::parLapply(cl, indices, check_parameter_set)
} else {
results <- lapply(start:end, check_parameter_set)
results <- lapply(indices, check_parameter_set)
}
return(results)
}


#' Run Parameter Set Checks
#'
#' This function runs checks on a range of parameter sets and provides a detailed report on the results.
#' This function runs checks on a vector of parameter sets and provides a detailed report on the results.
#' It can execute the checks either sequentially or in parallel.
#'
#' @param start The starting index of the parameter sets to check (default is 1).
#' @param end The ending index of the parameter sets to check (default is 10,000).
#' @param indices A vector of indices of the parameter sets to check. Default is `1:10000`.
#' @param verbose Logical. If `TRUE`, detailed output of the process is provided (default is `TRUE`).
#' @param parallel Logical. If `TRUE`, the checks are run in parallel using multiple cores; otherwise, they are run sequentially (default is `TRUE`).
#' @param store_output Logical. If `TRUE`, the function will store the IDs of the successful checks and the parameter sets that encountered errors (default is `FALSE`).
#'
#' @return A list containing the success summary, error summary, and optionally the IDs and error parameter sets if `store_output` is `TRUE`.
#'
#' @export
orderly_prod <- function(start = 1, end = 10000, verbose = TRUE, parallel = TRUE, store_output = FALSE) {
orderly_prod <- function(indices = 1:10000, verbose = TRUE, parallel = TRUE, store_output = FALSE) {

t0 <- Sys.time()

# Perform the checks
results <- execute_checks(start, end, parallel)
results <- execute_checks(indices, parallel)

# Process results
success_results <- lapply(results, function(x) if (x$success) list(parameter_set = x$parameter_set, id = x$id))
Expand Down Expand Up @@ -96,7 +95,7 @@ orderly_prod <- function(start = 1, end = 10000, verbose = TRUE, parallel = TRUE
cat("parameter_set:", res$parameter_set, "- Error:", res$error, "\n")
}
}
cat(end - start + 1, "total packets processed in:", elapsed_time, "seconds\n")
cat(length(indices), "total packets processed in:", elapsed_time, "seconds\n")
}

# Print the results summary
Expand Down
8 changes: 3 additions & 5 deletions man/execute_checks.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 3 additions & 6 deletions man/orderly_prod.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 301f8d2

Please sign in to comment.