[Discussion]: Handling operations that use/modify RNG
まだ誰も着手していません。
評価
調査の方向性
within と teal.code::eval_code のコードパスから始め、次に get_code(names = ...) とコードパーサーがどのように部分コードを構築するかを追跡してください。seed の追跡と再現性を理解するため、issue 278 とリンクされている RNG の参照を読んでください。完了とは、部分コードの実行におけるランダム操作について、コントリビューターが再現可能なポリシーに合意し、それを実装することを意味します。
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- R
- スター
- 12
- フォーク
- 12
- 平均マージ
- 4日 22時間
- マージ済み PR(30日)
- 3
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
pharmaverse/teal.code のほかの issue
-
enhancement
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
pharmaverse/teal.code#305 ·
-
[Feature Request]: High cyclomatic complexity leds to bad readability対応中かも @llrs-roche が 87 日前に担当しました。 オープンenhancement
難易度 3/5 3〜5日 初心者へのやさしさ 45/100
pharmaverse/teal.code#295 ·
-
bug core
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
pharmaverse/teal.code#275 ·
-
This is test issue to test copilot capabilities対応中かも @copilot-swe-agent が 484 日前に担当しました。 オープンbug
pharmaverse/teal.code#266 · リアクション 1 件 · 担当者 1 名 ·
-
core enhancement
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
pharmaverse/teal.code#204 ·
pharmaverse/teal.code の issue をすべて見る
似ている issue
-
bug
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
Bioconductor/BiocParallel#289 ·
-
automation
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
waldronlab/BugSigDBcuration#2224 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
merliseclyde/BAS#118 ·