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

Force TFP modules to load, fix model init #5

Merged
merged 12 commits into from
Jun 27, 2024
9 changes: 5 additions & 4 deletions .github/workflows/R-CMD-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ on:

jobs:
R-CMD-check:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
timeout-minutes: 10

strategy:
matrix:
os: [ubuntu-latest, macos-latest]

steps:
- name: Check out repository
uses: actions/checkout@v4
Expand All @@ -20,9 +24,6 @@ jobs:
with:
python-version: "3.10"

- name: Install venv
run: sudo apt-get install python3-virtualenv

- name: Set up R
uses: r-lib/actions/setup-r@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Config/testthat/edition: 3
URL: https://liesel-devs.github.io/rliesel/
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ importFrom(mgcv,gam)
importFrom(mgcv,smooth2random)
importFrom(reticulate,import)
importFrom(reticulate,np_array)
importFrom(reticulate,py_get_attr)
importFrom(reticulate,py_has_attr)
importFrom(reticulate,py_to_r)
importFrom(reticulate,use_virtualenv)
Expand Down
5 changes: 2 additions & 3 deletions R/reticulate.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,8 @@ NULL
use_tmp_liesel_venv <- function(...) {
path <- tempdir()

virtualenv_create(path, ...)
virtualenv_install(path, "git+https://github.com/liesel-devs/liesel.git",
ignore_installed = TRUE)
virtualenv_create(path, packages = NULL, ...)
virtualenv_install(path, "liesel", ignore_installed = TRUE)
try(virtualenv_install(path, "pygraphviz", ignore_installed = TRUE))
use_virtualenv(path, required = TRUE)

Expand Down
24 changes: 16 additions & 8 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,31 @@ plot.liesel.model.model.Model <- function(x, nodes = FALSE, ...) {
}


#' @importFrom reticulate py_has_attr
#' @importFrom reticulate py_get_attr py_has_attr

get_distribution <- function(x) {
if (is.character(x) && py_has_attr(.lsld, x)) {
return(py_get_attr(.lsld, x, silent = FALSE))
}

if (is.character(x)) {
if (py_has_attr(.lsld, x)) .lsld[[x]] else .tfd[[x]]
} else {
x
return(py_get_attr(.tfd, x, silent = FALSE))
}

x
}


#' @importFrom reticulate py_has_attr
#' @importFrom reticulate py_get_attr py_has_attr

get_bijector <- function(x) {
if (is.character(x) && py_has_attr(.lslb, x)) {
return(py_get_attr(.lslb, x, silent = FALSE))
}

if (is.character(x)) {
if (py_has_attr(.lslb, x)) .lslb[[x]] else .tfb[[x]]
} else {
x
return(py_get_attr(.tfb, x, silent = FALSE))
}

x
}
Loading