Save 37% off PRO during our Black Friday Sale! »

{targets}でワークフローを管理せよ / Workflow management with targets

{targets}でワークフローを管理せよ / Workflow management with targets

D12a80cab206033a820ccff8319f957b?s=128

Uryu Shinya

October 30, 2021
Tweet

Transcript

  1. @u_ribo TOKYO.R #95 Shinya Uryu

  2. γʔγϡϙεͷؠ ࡞ۀͷ΍Γ௚͠ʹۤ͠Ήσʔλ෼ੳऀͨͪ

  3. ϫʔΫϑϩʔͷґଘؔ܎ (BSSFUUBOE)BEMFZ  ΑΓ࡞੒

  4. ϫʔΫϑϩʔͷґଘؔ܎ ্ྲྀͰߦͬͨมߋ͕ԼྲྀʹӨڹ 🔥 🔥 🔥 🔥 🔥

  5. ࠶ݱੑͱ࣮ߦ࣌ؒͷδϨϯϚ 🔥 ϫʔΫϑϩʔʹมߋ͕ՃΘͬͨ࣌ Ͳ͏͢Δʁ ࠶ݱੑ ࣮ߦ࣌ؒ ϑΥϧμ؅ཧ ίʔυΛ࢒͢ ˓ º

    ख͕͔͔ؒΔ ݁ՌʢσʔλʣΛ ࢒͢ º ˓ ख͕͔͔ؒΔ
  6. {targets} Dynamic Function-Oriented 'Make'-Like Declarative Workflows ؔ਺ࢦ޲ϓϩάϥϛϯάͱએݴܕͷϫʔΫϑϩʔ ͕ಛ௃ ౷ܭɾσʔλαΠΤϯεͷͨΊͷύΠϓϥΠϯπʔϧ ίʔυͱσʔλͷ؅ཧ͕༰қ

    \ESBLF^ύοέʔδͷޙܧ
  7. {targets}ΛקΊΔཧ༝ ࡞ۀͷྲྀΕͷࢹ֮Խ σʔλɾίʔυͷϒϥοΫϘοΫεԽΛ๷͙ શମͷॲཧΛ؆ܿʹ ॲཧΛؔ਺Խ͢Δ͜ͱͰอकੑ΋޲্ ίʔυɺσʔλ؅ཧͷ൥Θ͔͠͞Βͷ୤٫ मਖ਼ɾ௥Ճ࡞ۀͷࡍͷෛ୲͕ݮগ ϫʔΫϑϩʔʹΑΔґଘؔ܎ͷ೺Ѳ

  8. ࠓ೔࿩ʢͤc͞ʣͳ͍͜ͱ 5BSHFU.BSLEPXO σόοάͷํ๏ ͜ΕΒͷ಺༰͸ϚχϡΞϧΛࢀߟ @UBSHFUTΦϒδΣΫτͷ؅ཧ https://books.ropensci.org/targets/ 3.BSLEPXOจॻ಺෦ͰύΠϓϥΠϯΛఆٛ 5BSHFU.BSLEPXOݕূϝϞUFSBTIJNDPN https://terashim.com/posts/target-markdown/ ͳͲ

  9. {targets}ͷύΠϓϥΠϯ ࣮ߦ݁ՌΛ಺෦ʹอଘɻ࠶࣮ߦ࣌ɺલճͷ࣮ߦ͔࣌Βɹ มߋͷͳ͍ॲཧʢλʔήοτʣΛεΩοϓ ࣮ߦ࣌ؒͷ୹ॖɺ ... ϫʔΫϑϩʔશମͷґଘؔ܎ ʢίʔυɺσʔλɺ্ྲྀͰͷॲཧ಺༰ʣΛ؂ࢹ ࠶ݱੑ͕อূ͞ΕΔɻ ϑΥϧμ؅ཧͷ൥Θ͔͠͞Βղ์͞ΕΔɻ 4UBOͳͲͷ࣮ߦʹ࣌ؒΛཁ͢Δॲཧ΍ػցֶशͷ࣮ݧʹద͢Δɻ

  10. {targets}ͷجૅ αϯϓϧϦϙδτϦ IUUQTHJUIVCDPNVSJCPUBML@@UPLZPS

  11. \UBSHFUT^Λ࢖ͬͨϓϩδΣΫτͷجຊ ├─_targets.R ├─ R/ ├── function.R ├─ data/ ├── raw_data.csv

    └─ hoge.Rproj \UBSHFUT^ʹΑΔύΠϓϥΠϯͷ ࣮ߦखॱΛهࡌɺ ࣮ߦʹඞཁͳύοέʔδɾؔ਺ಡΈࠐ Έ΍ͦͷଞͷΦϓγϣϯΛؚΊΔɻ 5BSHFUεΫϦϓτϑΝΠϧ @UBSHFUT3
  12. ͭͷॲཧ ͔ΒͳΔϫʔΫϑϩʔ @UBSHFUT3ʹλʔήοτͱͳΔॲཧΛهड़ library(targets) list( tar_target( my_mtcars, subset(mtcars, cyl ==

    6)), tar_target( dist_histogram, hist(my_mtcars$disp)), tar_target( lm_res, lm(mpg ~ wt, mtcars)) ) MJTU Λ࢖ͬͯύΠϓϥΠϯΛఆٛ ⁞   ⁠ ݸผͷॲཧ͸UBS@UBSHFU Ͱࢦఆ UBS@UBSHFU ໊લ ॲཧ಺༰ my_mtcars <- subset(mtcars, cyl == 6) UBS@NBLF ͰύΠϓϥΠϯͷ࣮ߦ ࣮ߦ؀ڥͱ͸ҟͳΔ3ηογϣϯͰ ͕ߦΘΕΔΠϝʔδ ⁞   ⁠ _targets.R
  13. tar_make()ύΠϓϥΠϯͷ࣮ߦ TUBSU CVJME 5BSHFUʹมߋ͕͋Ε͹ ʢΩϟογϡ͕ར༻͞ΕΔʣ 5BSHFUͷॲཧ͕࣮ߦ σʔλετϨʔδʢޙड़ʣʹ ͳ͚Ε͹TLJQ ࠷ॳͷUBS@NBLF ೋ౓໨ͷUBS@NBLF

  14. tar_visnetwork()ϫʔΫϑϩʔͷՄࢹԽ library(targets) list( tar_target( my_mtcars, subset(mtcars, cyl == 6)), tar_target(

    dist_histogram, hist(my_mtcars$disp)), tar_target( lm_res, lm(mpg ~ wt, mtcars)) ) ॲཧ಺༰ͷґଘؔ܎͕໌֬ʹ ⁞   ⁠ Ͳͷॲཧ͕มߋ͞Εͨʁ ΤϥʔՕॴͷಛఆ͕༰қʹ _targets.R
  15. tar_read()tar_load()݁Ռͷ෮ݩ ॲཧ݁Ռ͸@UBSHFUTʹ஝ੵ͞Ε͍ͯΔ tar_read(lm_res) #> Call: #> lm(formula = mpg ~

    wt, data = mtcars) #> #> Coefficients: #> (Intercept) wt #> 37.285 -5.344 UBS@MPBE Ͱ࡞ۀۭؒʹ ΦϒδΣΫτͱͯ͠อଘ UBS@SFBE ͰಡΈࠐΈ ʢग़ྗʣ ࠶ݱੑͷ޲্ɾ࣌ؒͷ୹ॖ
  16. ଟ༷ͳσʔλετϨʔδ ├─ _targets/ ├── meta/meta ├── objects/ ├──── my_mtcars ├────

    dist_histogram ├──── lm_res ͲͷΑ͏ͳσʔλ͕͋Δ͔ʜ UBS@NFUB ύΠϓϥΠϯͰੜ੒͞Εͨ݁ՌΛ@UBSHFUT಺Ͱ؅ཧ σϑΥϧτͰ͸SET UBS@UBSHFU ʜ GPSNBU ͰࢦఆՄೳ GTU GFBUIFS QBSRVFU BXT
  17. {targets}ͷਪ͠ػೳ

  18. ਪ͠ϒϥϯν ϞσϧͷύϥϝʔλΛมߋͯ݁͠ՌΛൺֱ͍ͨ͠ ࣮ݧͱͯ͠ద౰ͳ஋ΛೖΕͯࢼ͍ͨ͠ ࡞ਤͷݟͨ໨Λม͑ΔͷʹҰ෦ͷ৭͚ͩมߋͯ͠Έ͍ͨ ίʔυʹ࢒͢ʁ ݁ՌΛ؅ཧ͢Δͷ͸໘౗ʜ UBS@SFBE ʜ CSBODIFT list(…

    tar_target(activations, c("relu", "sigmoid")), tar_target( run, test_model(act1 = activations, churn_data, churn_recipe), pattern = map(activations) ),…) 5BSHFUT͕Α͠ͳʹ؅ཧʂ QBUUFSOҾ਺ JUFSBUJPOҾ਺ ׆ੑԽؔ਺ͷࢦఆΛύλʔϯ༻ҙ _targets.R
  19. ਪ͠ߴੑೳܭࢉ UBS@UBSHFU ಺Ͱͷ੾Γସ͑͸EFQMPZNFOUҾ਺ͰࢦఆɻlNBJOz·ͨ͸lXPSLFSz UBS@NBLF@DMVTUFSNR ෛ୲ͷେ͖ͳॲཧ΋ߴ଎ʹ {clustermq} {future} UBS@NBLF@GVUVSF options( clustermq.scheduler

    = "multiprocess") library(future) library(future.callr) plan(callr) list( tar_target(data, get_data()), tar_target(fast_fit, fit_small_model(data)), tar_target(plot_1, make_plot(fast_fit))) _targets.R
  20. R targetopia tarchetypes::tar_render() 3NEϑΝΠϧͷग़ྗΛ࣮ߦ stantargets::tar_stan_compile() TUBOϑΝΠϧͷίϯύΠϧ ॲཧ಺༰ΛύοέʔδԽ ൚༻తͳ ༻్ʹಛԽͨؔ͠਺Λఏڙ