bayesflow-org / bayesflow

A Python library for amortized Bayesian workflows using generative neural networks.
https://bayesflow.org/
MIT License
372 stars 52 forks source link

Calling bayesflow from R #218

Closed marvinschmitt closed 2 weeks ago

eodole commented 3 weeks ago

Commit : 60a2fca5f512f504f79837237590847270b2a0e5 Issue: This issue is in reference to the two_moons.rmd in the r-notebook branch, where we are trying to recreate the two moons tutorial in R via the package reticulate.

R stores all numbers as float64 where as tensorflow in python wants to have a float32. I tried changing the forward model function so that it would explicitly generate float32, but when it is called later by another function to sample training data, the training data which is stored in R, is in the default number type float64.

Tried: history <- approximator$fit( epochs = 3L, dataset = training_dataset, validation_data = validation_dataset )

Full Error:


tensorflow.python.framework.errors_impl.InvalidArgumentError: cannot compute Mul as input #1(zero-based) was expected to be a float tensor but is a double tensor [Op:Mul] name: 
Run `reticulate::py_last_error()` for details.

9.
stop(structure(list(message = "tensorflow.python.framework.errors_impl.InvalidArgumentError: cannot compute Mul as input #1(zero-based) was expected to be a float tensor but is a double tensor [Op:Mul] name: \n\033[90mRun \033]8;;rstudio:run:reticulate::py_last_error()\a`reticulate::py_last_error()`\033]8;;\a for details.\033[39m", 
call = py_call_impl(callable, call_args$unnamed, call_args$named)), class = c("tensorflow.python.framework.errors_impl.InvalidArgumentError", 
"tensorflow.python.framework.errors_impl.OpError", "python.builtin.Exception", 
"python.builtin.BaseException", "python.builtin.object", "error", ...

8.
raise_from_not_ok_status at ops.py#5983

7.
error_handler at traceback_utils.py#153

6.
compute_metrics at flow_matching.py#117

5.
compute_metrics at continuous_approximator.py#95

4.
build_from_data at approximator.py#23

3.
fit at approximator.py#82

2.
fit at continuous_approximator.py#109

1.
approximator$fit(epochs = 3L, dataset = training_dataset, validation_data = validation_dataset)```