Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Description: API server for odin models, using porcelain/plumber.
License: MIT + file LICENSE
Encoding: UTF-8
Roxygen: list(markdown = TRUE, roclets = c("rd", "namespace", "porcelain::porcelain_roclet"))
RoxygenNote: 7.2.1
RoxygenNote: 7.3.3
URL: https://github.com/mrc-ide/odin.api
BugReports: https://github.com/mrc-ide/odin.api/issues
Imports:
Expand Down
14 changes: 14 additions & 0 deletions R/api.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ model_compile <- function(data, pretty = FALSE) {
}


##' @porcelain POST /compile2 => json(compile2_response)
##' body data :: json(compile2_request)
model_compile2 <- function(data) {
data <- jsonlite::fromJSON(data, simplifyDataFrame = FALSE)
result <- odin2_js_validate(data$model)
if (result$valid) {
code <- odin2::odin_show_js(data$model, "text", check_bounds = FALSE)
code <- c(code, "odin_system;")
result$model <- scalar(paste(code, collapse = "\n"))
}
result
}


##' @porcelain GET /support/runner-ode => json
support_runner_ode <- function() {
code <- read_string(system_file("js/odin.js", "odin"))
Expand Down
14 changes: 14 additions & 0 deletions R/odin.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ odin_js_model <- function(code) {
}


odin2_js_validate <- function(code) {
result <- odin2::odin_validate(code, "text", check_bounds = FALSE)

if (!result$success) {
err <- result$error
list(valid = scalar(FALSE),
error = odin_error_detail(err$message, err$src$start))
} else {
list(valid = scalar(TRUE),
metadata = result$result)
}
}


odin_js_validate <- function(code, requirements) {
options <- odin::odin_options(target = "js")
result <- odin::odin_validate(code, "text", options)
Expand Down
9 changes: 9 additions & 0 deletions R/porcelain.R

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

53 changes: 50 additions & 3 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM rocker/r-ver:4.1.2
FROM rocker/r-ver:4.4.3

RUN apt-get update && apt-get install -y --no-install-recommends \
libcurl4-openssl-dev \
Expand All @@ -14,14 +14,61 @@ COPY docker/Rprofile.site /usr/local/lib/R/etc/Rprofile.site
# More cache-friendly installation of some dependencies:
RUN install2.r --error \
--repos=https://mrc-ide.github.io/drat \
--repos=https://packagemanager.rstudio.com/all/__linux__/focal/latest \
--repos=https://packagemanager.rstudio.com/all/__linux__/noble/latest \
docopt \
jsonlite \
logr \
later \
fastmap \
otel \
ps \
Rcpp \
curl \
crayon \
httpuv \
lifecycle \
magrittr \
mime \
promises \
rlang \
sodium


RUN install2.r --error \
--repos=https://mrc-ide.github.io/drat \
--repos=https://packagemanager.rstudio.com/all/__linux__/noble/latest \
stringi \
swagger \
webutils \
common \
withr \
R6 \
cinterpolate \
deSolve \
digest \
glue \
ring \
callr \
cli \
desc \
processx

RUN install2.r --error \
--repos=https://mrc-ide.github.io/drat \
--repos=https://packagemanager.rstudio.com/all/__linux__/noble/latest \
odin \
pkgbuild \
pkgbuild

RUN install2.r --error \
--repos=https://mrc-ide.github.io/drat \
--repos=https://packagemanager.rstudio.com/all/__linux__/noble/latest \
porcelain

RUN install2.r --error \
remotes

RUN installGithub.r mrc-ide/odin2@9db29f1

COPY DESCRIPTION /tmp/DESCRIPTION

# Then get the full list via remotes
Expand Down
2 changes: 1 addition & 1 deletion docker/Rprofile.site
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
options(repos = c(CRAN = 'https://packagemanager.rstudio.com/all/__linux__/focal/latest'), download.file.method = 'libcurl')
options(repos = c(CRAN = 'https://packagemanager.rstudio.com/all/__linux__/noble/latest'), download.file.method = 'libcurl')
options(HTTPUserAgent = sprintf("R/%s R (%s)", getRversion(),
paste(getRversion(), R.version$platform,
R.version$arch, R.version$os)))
11 changes: 11 additions & 0 deletions inst/schema/compile2_request.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"model": {
"$ref": "model.json"
}
},
"additionalProperties": false,
"required": ["model"]
}
35 changes: 35 additions & 0 deletions inst/schema/compile2_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",

"oneOf": [
{
"type": "object",
"properties": {
"valid": {
"enum": [ true ]
},
"metadata": {
"type": "object"
},
"model": {
"type": "string"
}
},
"additionalProperties": false,
"required": ["valid", "metadata", "model"]
},
{
"type": "object",
"properties": {
"valid": {
"enum": [ false ]
},
"error": {
"$ref": "diagnostic.json"
}
},
"additionalProperties": false,
"required": ["valid", "error"]
}
]
}
Loading