[Discussion]: Handling operations that use/modify RNG
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Anfängerfreundlichkeit
- 25/100
Rechercherichtung
Beginnen Sie mit den Codepfaden within und teal.code::eval_code und verfolgen Sie dann, wie get_code(names = ...) und der Code-Parser partiellen Code erstellen. Lesen Sie Issue 278 und die verknüpften RNG-Referenzen, um Seed-Tracking und Reproduzierbarkeit zu verstehen. Als erledigt gilt die Aufgabe, wenn sich die Beitragenden auf eine reproduzierbare Richtlinie für Zufallsoperationen bei der Ausführung partiellen Codes einigen und diese implementieren.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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.
- Vorherrschende Sprache
- R
- Sterne
- 12
- Forks
- 11
- Ø Merge
- 8 T. 15 Std.
- Gemergte PRs (30 T.)
- 2
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus insightsengineering/teal.code
-
Move to PharmaverseEvtl. vergeben @llrs-roche hat das vor 38 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
insightsengineering/teal.code#292 ·
-
[Feature Request]: High cyclomatic complexity leds to bad readabilityEvtl. vergeben @llrs-roche hat das vor 39 Tagen übernommen. Offenenhancement
Schwierigkeit 3/5 3-5 Tage Anfängerfreundlichkeit 45/100
insightsengineering/teal.code#295 ·
-
bug core
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 45/100
insightsengineering/teal.code#275 ·
-
bug core
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 38/100
insightsengineering/teal.code#272 ·
-
This is test issue to test copilot capabilitiesEvtl. vergeben @copilot-swe-agent hat das vor 436 Tagen übernommen. Offenbug
insightsengineering/teal.code#266 · 1 Reaktion · 1 zugewiesene Person ·
Alle Issues in insightsengineering/teal.code
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 67/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 64/100
mitchelloharawild/ggtime#39 ·
-
enhancement good first issue help wanted
Schwierigkeit 2/5 Ein halber Tag Anfängerfreundlichkeit 82/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 82/100
GSK-Biostatistics/multigrain#43 ·
Maintainer antworten meist innerhalb von 1 Tag