Skip to content

Commit

Permalink
fix recompiling models with PM_load
Browse files Browse the repository at this point in the history
  • Loading branch information
mnneely committed Jan 7, 2025
1 parent d6407c3 commit 375299f
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 14 deletions.
21 changes: 12 additions & 9 deletions R/PM_fit.R
Original file line number Diff line number Diff line change
Expand Up @@ -430,15 +430,18 @@ PM_fit <- R6::R6Class(
binary_path = NULL,
setup_rust_execution = function() {

if (!file.exists(self$model$binary_path)) {
self$model$compile()
if (!file.exists(self$model$binary_path)) {
cli::cli_abort(c(
"x" = "Rust has not been built.",
"i" = "Make sure the model was built correcly when calling {.fn PM_model$new}"
))
}
}
# check if compiled and if not, do so
self$model$compile()

# if (is.null(self$model$binary_path)) {
# self$model$compile()
# if (!file.exists(self$model$binary_path)) {
# cli::cli_abort(c(
# "x" = "Rust has not been built.",
# "i" = "Make sure the model was built correcly when calling {.fn PM_model$new}"
# ))
# }
# }
# cwd <- getwd()
# self$model$write_rust()

Expand Down
7 changes: 3 additions & 4 deletions R/PM_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ PM_model$new <- function(model, ...) {
} else {
cli::cli_abort(c("x" = "Non supported model type: {typeof(model)}"))
}
if (getPMoptions()$backend == "rust") {
model$compile()
}
# if (getPMoptions()$backend == "rust") {
# model$compile()
# }
return(model)
}

Expand Down Expand Up @@ -789,7 +789,6 @@ PM_model_list <- R6::R6Class("PM_model_list",
if (!is.null(self$binary_path) && file.exists(self$binary_path)) {
return()
}

temp_model <- file.path(tempdir(), "temp_model.txt")
self$write_rust(temp_model)
model_path <- tempfile(pattern = "model_", fileext = ".pmx")
Expand Down
2 changes: 1 addition & 1 deletion R/PM_sim.R
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,6 @@ PM_sim <- R6::R6Class(
if (length(postToUse) > 0) {
# simulating from posteriors, each posterior matched to a subject
# need to set theta as the posterior mean or median for each subject
# code here...

ans <- NULL
data_list <- list()
Expand Down Expand Up @@ -1306,6 +1305,7 @@ PM_sim <- R6::R6Class(
# call simulator and process results
getSim = function(thisPrior, template, mod, noise2){
thetas <- thisPrior$thetas %>% select(-prob) %>% as.matrix()
mod$compile() # check if compiled and if not, do so
sim_res <- mod$simulate_all(template, thetas)
sim_res$.id <- template$standard_data$id[match(sim_res$id, template$standard_data$id)]
sim_res <- sim_res %>% rename(comp = state_index, nsim = spp_index, amt = state) %>%
Expand Down
21 changes: 21 additions & 0 deletions man/figures/lifecycle-deprecated.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions man/figures/lifecycle-experimental.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions man/figures/lifecycle-stable.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions man/figures/lifecycle-superseded.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 375299f

Please sign in to comment.