Skip to content

Commit ddb98e9

Browse files
committed
launchers remember arguments
1 parent 40e0909 commit ddb98e9

File tree

5 files changed

+64
-61
lines changed

5 files changed

+64
-61
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
* `everywhere()` now returns a list of mirai, which may be waited for and inspected (thanks @dgkf #164).
2020
* `everywhere()` drops argument '.serial' as serialization configurations are now registered via an argument at `daemons()`.
2121
* `launch_local()` and `launch_remote()` simplified to take the argument 'n' instead of 'url' for how many daemons to launch.
22+
* `launch_local()` and `launch_remote()` now launch daemons with the originally-supplied arguments by default.
2223
* `launch_local()` now returns the number of daemons launched rather than invisible NULL.
2324
* `ssh_config()` simplified to take the argument 'port' instead of 'host'. For SSH tunnelling, this is the port that will be used, and the hostname is now required to be '127.0.0.1' (no longer accepting 'localhost').
2425
* `daemon()` gains the new argument 'dispatcher', which should be set to `TRUE` when connecting to dispatcher and `FALSE` when connecting directly to host.

R/daemons.R

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ daemons <- function(n, url = NULL, remote = NULL, dispatcher = TRUE, ...,
250250
if (is.null(envir)) {
251251
envir <- init_envir_stream(seed)
252252
launches <- 0L
253+
dots <- parse_dots(...)
254+
output <- attr(dots, "output")
253255
switch(
254256
parse_dispatcher(dispatcher),
255257
{
@@ -260,8 +262,6 @@ daemons <- function(n, url = NULL, remote = NULL, dispatcher = TRUE, ...,
260262
{
261263
tls <- configure_tls(url, tls, pass, envir, returnconfig = FALSE)
262264
cv <- cv()
263-
dots <- parse_dots(...)
264-
output <- attr(dots, "output")
265265
urld <- local_url()
266266
sock <- req_socket(urld)
267267
res <- launch_sync_dispatcher(sock, sock, wa52(urld, dots, url), output, tls, pass, serial)
@@ -273,8 +273,6 @@ daemons <- function(n, url = NULL, remote = NULL, dispatcher = TRUE, ...,
273273
n <- if (missing(n)) length(url) else if (is.numeric(n) && n >= 1L) as.integer(n) else stop(._[["n_one"]])
274274
tls <- configure_tls(url, tls, pass, envir, returnconfig = FALSE)
275275
cv <- cv()
276-
dots <- parse_dots(...)
277-
output <- attr(dots, "output")
278276
urld <- local_url()
279277
urlc <- sprintf("%s%s", urld, "c")
280278
sock <- req_socket(urld)
@@ -286,7 +284,7 @@ daemons <- function(n, url = NULL, remote = NULL, dispatcher = TRUE, ...,
286284
},
287285
stop(._[["dispatcher_args"]])
288286
)
289-
`[[<-`(.., .compute, `[[<-`(`[[<-`(envir, "sock", sock), "n", launches))
287+
`[[<-`(.., .compute, `[[<-`(`[[<-`(`[[<-`(envir, "sock", sock), "n", launches), "dots", dots))
290288
if (length(remote))
291289
launch_remote(n = n, remote = remote, tls = envir[["tls"]], ..., .compute = .compute)
292290
} else if (force) {
@@ -345,7 +343,7 @@ daemons <- function(n, url = NULL, remote = NULL, dispatcher = TRUE, ...,
345343
},
346344
stop(._[["dispatcher_args"]])
347345
)
348-
`[[<-`(.., .compute, `[[<-`(`[[<-`(envir, "sock", sock), "n", n))
346+
`[[<-`(.., .compute, `[[<-`(`[[<-`(`[[<-`(envir, "sock", sock), "n", n), "dots", dots))
349347
} else if (force) {
350348
daemons(0L, .compute = .compute)
351349
return(daemons(n = n, url = url, remote = remote, dispatcher = dispatcher, ...,

R/launchers.R

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (C) 2023-2024 Hibiki AI Limited <info@hibiki-ai.com>
1+
# Copyright (C) 2023-2025 Hibiki AI Limited <info@hibiki-ai.com>
22
#
33
# This file is part of mirai.
44
#
@@ -35,9 +35,11 @@
3535
#'
3636
#' \strong{or} for \code{launch_remote} only, a \sQuote{miraiCluster} or
3737
#' \sQuote{miraiNode}.
38-
#' @param ... (optional) additional arguments passed through to
39-
#' \code{\link{daemon}}. These include \sQuote{autoexit}, \sQuote{cleanup},
40-
#' and \sQuote{output}.
38+
#' @param ... (optional) arguments passed through to \code{\link{daemon}}. These
39+
#' include \sQuote{autoexit}, \sQuote{cleanup}, \sQuote{output},
40+
#' \sQuote{maxtasks}, \sQuote{idletime} and \sQuote{walltime}. Only supply to
41+
#' override arguments originally provided to \code{\link{daemons}}, otherwise
42+
#' those will be used instead.
4143
#' @param tls [default NULL] required for secure TLS connections over
4244
#' 'tls+tcp://'. Zero-configuration TLS certificates generated by
4345
#' \code{\link{daemons}} are automatically passed to the daemon, without
@@ -78,7 +80,7 @@ launch_local <- function(n = 1L, ..., tls = NULL, .compute = "default") {
7880
is.null(envir) && stop(._[["daemons_unset"]])
7981
url <- envir[["urls"]][1L]
8082
write_args <- if (length(envir[["msgid"]])) wa32 else wa3
81-
dots <- parse_dots(...)
83+
dots <- if (missing(..1)) envir[["dots"]] else parse_dots(...)
8284
output <- attr(dots, "output")
8385
if (is.null(tls)) tls <- envir[["tls"]]
8486
for (i in seq_len(n))
@@ -117,7 +119,7 @@ launch_remote <- function(n = 1L, remote = remote_config(), ..., tls = NULL, .co
117119
write_args <- if (length(envir[["msgid"]])) wa32 else wa3
118120
is.null(envir) && stop(._[["daemons_unset"]])
119121
url <- envir[["urls"]][1L]
120-
dots <- parse_dots(...)
122+
dots <- if (missing(..1)) envir[["dots"]] else parse_dots(...)
121123
if (is.null(tls)) tls <- envir[["tls"]]
122124

123125
command <- remote[["command"]]

man/launch_local.Rd

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vignettes/mirai.Rmd

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@ To wait for and collect the return value, use the mirai's `[]` method:
6262

6363
``` r
6464
m[]
65-
#> [1] 3.629774 4.477807 2.517551 4.014334 3.900383
65+
#> [1] 4.002576 1.751233 3.226821 5.200427 3.284885
6666
```
6767
As a mirai represents an async operation, it is never necessary to wait for it. Other code can continue to be run. Once it completes, the return value automatically becomes available at `$data`.
6868

6969
``` r
7070
m
7171
#> < mirai [$data] >
7272
m$data
73-
#> [1] 3.629774 4.477807 2.517551 4.014334 3.900383
73+
#> [1] 4.002576 1.751233 3.226821 5.200427 3.284885
7474
```
7575
For easy programmatic use of `mirai()`, '.expr' accepts a pre-constructed language object, and also a list of named arguments passed via '.args'. So, the following would be equivalent to the above:
7676

@@ -82,7 +82,7 @@ args <- list(time = x$time, mean = x$mean)
8282

8383
m <- mirai(.expr = expr, .args = args)
8484
m[]
85-
#> [1] 4.4081347 3.0966171 0.9202833 3.8138802 3.0876354
85+
#> [1] 3.916442 2.951214 2.044501 2.688432 5.520616
8686
```
8787

8888
[&laquo; Back to ToC](#table-of-contents)
@@ -162,8 +162,8 @@ for (i in 1:10) {
162162
#> iteration 4 successful
163163
#> iteration 5 successful
164164
#> iteration 6 successful
165-
#> Error: random error
166165
#> iteration 7 successful
166+
#> Error: random error
167167
#> iteration 8 successful
168168
#> iteration 9 successful
169169
#> iteration 10 successful
@@ -203,7 +203,7 @@ status()
203203
#> [1] 6
204204
#>
205205
#> $daemons
206-
#> [1] "abstract://d630a1f33d7fadc9a81b61f3"
206+
#> [1] "abstract://2591aab600fb24a816361f11"
207207
#>
208208
#> $mirai
209209
#> awaiting executing completed
@@ -237,7 +237,7 @@ status()
237237
#> [1] 6
238238
#>
239239
#> $daemons
240-
#> [1] "abstract://883b0bfb01c45eb4ba84da75"
240+
#> [1] "abstract://42971685f607db97affae685"
241241
```
242242
This implementation sends tasks immediately, and ensures that tasks are evenly-distributed amongst daemons. This means that optimal scheduling is not guaranteed as the duration of tasks cannot be known *a priori*. As an example, tasks could be queued at a daemon behind a long-running task, whilst other daemons are idle having already completed their tasks.
243243

@@ -265,11 +265,11 @@ m <- mirai(capture.output(str(con)))
265265
m[]
266266
#> [1] "Formal class 'SQLiteConnection' [package \"RSQLite\"] with 8 slots"
267267
#> [2] " ..@ ptr :<externalptr> "
268-
#> [3] " ..@ dbname : chr \"/tmp/RtmpXee6o4/file5de7357bf52d\""
268+
#> [3] " ..@ dbname : chr \"/tmp/RtmpcbGRUv/filec92f21c2d747\""
269269
#> [4] " ..@ loadable.extensions: logi TRUE"
270270
#> [5] " ..@ flags : int 70"
271271
#> [6] " ..@ vfs : chr \"\""
272-
#> [7] " ..@ ref :<environment: 0x61e41ef88c10> "
272+
#> [7] " ..@ ref :<environment: 0x56a7cebba7d8> "
273273
#> [8] " ..@ bigint : chr \"integer64\""
274274
#> [9] " ..@ extended_types : logi FALSE"
275275
```
@@ -321,7 +321,7 @@ status()
321321
#> [1] 0
322322
#>
323323
#> $daemons
324-
#> [1] "tcp://hostname:32841"
324+
#> [1] "tcp://hostname:34975"
325325
#>
326326
#> $mirai
327327
#> awaiting executing completed
@@ -415,10 +415,10 @@ daemons(url = host_url())
415415
#> [1] 0
416416
launch_remote(2)
417417
#> [1]
418-
#> Rscript -e 'mirai::daemon("tcp://hostname:35843",rs=c(10407,296269407,1807473940,-1396830971,132034050,1244230043,-275785696),dispatcher=TRUE)'
418+
#> Rscript -e 'mirai::daemon("tcp://hostname:42961",rs=c(10407,90778926,-642612265,-394494420,-62569155,-851866918,-839171437),dispatcher=TRUE)'
419419
#>
420420
#> [2]
421-
#> Rscript -e 'mirai::daemon("tcp://hostname:35843",rs=c(10407,1651873135,1072546643,-1285228557,1977428147,-503395889,-2007462953),dispatcher=TRUE)'
421+
#> Rscript -e 'mirai::daemon("tcp://hostname:42961",rs=c(10407,-216293777,1029180408,-534177028,-534431600,821325985,425956901),dispatcher=TRUE)'
422422
daemons(0)
423423
#> [1] 0
424424
```
@@ -445,37 +445,37 @@ The generated self-signed certificate is available via `launch_remote()`. This f
445445
``` r
446446
launch_remote(1)
447447
#> [1]
448-
#> Rscript -e 'mirai::daemon("tls+tcp://hostname:37343",tls=c("-----BEGIN CERTIFICATE-----
448+
#> Rscript -e 'mirai::daemon("tls+tcp://hostname:42777",tls=c("-----BEGIN CERTIFICATE-----
449449
#> MIIFNzCCAx+gAwIBAgIBATANBgkqhkiG9w0BAQsFADAzMREwDwYDVQQDDAhrdW1h
450450
#> bW90bz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NmjQpzRVVCi
472+
#> 2Y/8RTrLFv+NFDMlug3uQV75AAv3u5CDaV2iWICMBdXCHbx/m5LfloiJcP6UxBCw
473+
#> ZwF+ga/hWMZKSPbbO8bq2gm7LYSk+bofCVxD5tAfufC++qDKjBMidYvkx2NktPOD
474+
#> bCGKF4aDSNaFw40F77HCjo+5jKw9Udja2q0GDAyRVJaFbaXZacinCtSD7Y9G7kgv
475+
#> gfNai0C921Vm5Wbinw68FF+RwmieZVRCyFRtTRM49hUpLEYcW94yN/z1bokcagGp
476+
#> 7sgSrU0ucE6dNN5rf90VoR66ZIfavwQcr9qzHSruqnRVxCY+N/hDLcAPcQ==
477477
#> -----END CERTIFICATE-----
478-
#> ",""),rs=c(10407,1949072686,-953576489,748965420,1706480957,-1854285094,-1987358061),dispatcher=TRUE)'
478+
#> ",""),rs=c(10407,-801997837,-995387240,-859772487,-1408070106,1245299311,563041764),dispatcher=TRUE)'
479479
```
480480
The printed value may be deployed directly on a remote machine.
481481

@@ -711,10 +711,10 @@ daemons(4)
711711
vec <- c(1, 1, 4, 4, 1, 1, 1, 1)
712712
system.time(mirai_map(vec, Sys.sleep)[])
713713
#> user system elapsed
714-
#> 0.006 0.005 4.008
714+
#> 0.005 0.006 4.007
715715
system.time(parLapply(cl, vec, Sys.sleep))
716716
#> user system elapsed
717-
#> 0.019 0.094 8.105
717+
#> 0.009 0.003 8.012
718718
```
719719
`.args` is used to specify further constant arguments to `.f` - the 'mean' and 'sd' in the example below:
720720

@@ -724,13 +724,13 @@ with(
724724
mirai_map(1:3, rnorm, .args = list(mean = 20, sd = 2))[]
725725
)
726726
#> [[1]]
727-
#> [1] 20.76691
727+
#> [1] 19.14144
728728
#>
729729
#> [[2]]
730-
#> [1] 20.77089 20.88563
730+
#> [1] 19.78728 21.73872
731731
#>
732732
#> [[3]]
733-
#> [1] 20.06892 15.61752 19.87714
733+
#> [1] 18.96823 16.64821 16.74725
734734
```
735735
Use `...` to further specify objects referenced but not defined in `.f` - the 'do' in the anonymous function below:
736736

@@ -742,16 +742,16 @@ ml <- mirai_map(
742742
)
743743
#> Warning: mirai is launching one local daemon for a map operation as none previously set
744744
ml
745-
#> < mirai map [2/3] >
745+
#> < mirai map [3/3] >
746746
ml[]
747747
#> $a
748-
#> [1] "24"
748+
#> [1] "1e"
749749
#>
750750
#> $b
751-
#> [1] ea 6c
751+
#> [1] af f5
752752
#>
753753
#> $c
754-
#> [1] "0d0643"
754+
#> [1] "786cf0"
755755
```
756756
Use of `mirai_map()` assumes that `daemons()` have previously been set. If not then one (non-dispatcher) daemon is set to allow the function to proceed. This ensures safe behaviour, but is unlikely to be optimal, so please ensure daemons are set beforehand.
757757

0 commit comments

Comments
 (0)