[Discussion]: Handling operations that use/modify RNG
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 25/100
Línea de trabajo
Comience con las rutas de código within y teal.code::eval_code y, después, siga cómo get_code(names = ...) y el analizador de código construyen código parcial. Lea issue 278 y las referencias de RNG vinculadas para comprender el seguimiento de seeds y la reproducibilidad. La tarea debe considerarse completada cuando los contribuidores acuerden e implementen una política reproducible para las operaciones aleatorias en la ejecución de código parcial.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
What is your question?
Per discussion with @llrs-roche, here are some topics for the contributors to discuss and research.
Problem
Random/stoichastic operations are not being well handled in within/teal.code::eval_code, in particular when code parse is being used.
In the section below you can observe that q |> get_code(names = "IRIS") is not fully reproducible as the random operations before were not included, nor was the RNG state updated before code execution
Reproducible code
This code highlights the 2 main problems:
set.seed()and other random operations are not kept in partial code (q |> get_code(names = "XXX"))MTCARS/IRISrandom operations are influenced by preceding code
library(teal.code)
q <- qenv() |>
within({
IRIS <- datasets::iris
MTCARS <- datasets::mtcars
set.seed(1)
.random <- runif(1)
IRIS$new <- runif(nrow(IRIS))
MTCARS$new <- runif(nrow(MTCARS))
})
q |> get_code() |> cat()
#> iris <- datasets::iris
#> mtcars <- datasets::mtcars
#> set.seed(1)
#> .random <- runif(1)
#> iris$new <- runif(nrow(iris))
#> mtcars$new <- runif(nrow(mtcars))
q |> get_code(names = "IRIS") |> cat()
#> IRIS <- datasets::iris
#> IRIS$new <- runif(nrow(IRIS))
local({
eval(str2expression(q |> get_code(names = "IRIS")))
q$IRIS |> rlang::hash() |> cat("# hash qenv IRIS\n")
IRIS |> rlang::hash() |> cat("# hash reproduced IRIS\n")
})
#> 9bba33c8ed5cd90cd13316f35f812f55 # hash qenv IRIS
#> c90a89c1814206bc19fdc32d04d1eefa # hash reproduced IRIS
q |> get_code(names = "MTCARS") |> cat()
#> MTCARS <- datasets::mtcars
#> MTCARS$new <- runif(nrow(MTCARS))
local({
eval(str2expression(q |> get_code(names = "MTCARS")))
q$mtcars |> rlang::hash() |> cat("# hash qenv MTCARS\n")
mtcars |> rlang::hash() |> cat("# hash reproduced MTCARS\n")
})
#> 2c0a8a99dc147d5445c3b49d035665b2 # hash qenv MTCARS
#> 6755d143ff87b73a1196c186cec7e86a # hash reproduced MTCARS
Reference material
- ref1: https://github.com/insightsengineering/teal.code/issues/278
- ref2: https://www.jottr.org/2020/09/21/detect-when-the-random-number-generator-was-used/
- Detect when random seed is modified
- ref3: https://blog.djnavarro.net/posts/2023-12-27_seedcatcher/
Possible set of solutions
- Use
teal.code::eval_code()and# @linksto XXXXXto include random operations- Status quo
- Cons: Requires character base code execution and requires manual maintenance
- Detect random seed at start and inform user
- Track random seed and incorporate it in code execution
- When using code parser, re-run partial code to sync modules with reproducible code (while keeping
set.seed()expressions)- cons: slow down teal app even more and data is not consistent with initial
dataargument in teal.
- cons: slow down teal app even more and data is not consistent with initial
- Always include
set.seed()expression and hope it doesn't have a big impact
Code of Conduct
- I agree to follow this project's Code of Conduct.
Contribution Guidelines
- I agree to follow this project's Contribution Guidelines.
Security Policy
- I agree to follow this project's Security Policy.
- Lenguaje dominante
- R
- Estrellas
- 12
- Forks
- 11
- Merge medio
- 8 d 15 h
- PR fusionados (30 d)
- 2
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de insightsengineering/teal.code
-
Move to PharmaversePosiblemente ocupada @llrs-roche la tomó hace 38 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
insightsengineering/teal.code#292 ·
-
[Feature Request]: High cyclomatic complexity leds to bad readabilityPosiblemente ocupada @llrs-roche la tomó hace 39 días. Abiertoenhancement
Dificultad 3/5 3-5 días Aptitud para principiantes 45/100
insightsengineering/teal.code#295 ·
-
bug core
Dificultad 3/5 1-2 días Aptitud para principiantes 45/100
insightsengineering/teal.code#275 ·
-
bug core
Dificultad 4/5 3-5 días Aptitud para principiantes 38/100
insightsengineering/teal.code#272 ·
-
This is test issue to test copilot capabilitiesPosiblemente ocupada @copilot-swe-agent la tomó hace 436 días. Abiertobug
insightsengineering/teal.code#266 · 1 reacción · 1 asignado ·
Todos los issues de insightsengineering/teal.code
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 64/100
mitchelloharawild/ggtime#39 ·
-
Add more snippets to R and JuliaAbiertoenhancement good first issue help wanted
Dificultad 2/5 Medio día Aptitud para principiantes 82/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
-
Link to the published paperAbierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 82/100
GSK-Biostatistics/multigrain#43 ·
Los mantenedores suelen responder en 1 día