Skip to content

Commit

Permalink
tweak errors / warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
shikokuchuo committed Oct 4, 2024
1 parent 5b74035 commit 4e5203f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 53 deletions.
6 changes: 3 additions & 3 deletions R/mirai-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
correct_context = "'host' must be specified if not using directly in a function argument",
daemons_unset = "daemons must be set to use launchers",
dispatcher_args = "'dispatcher' must be one of 'process', 'thread' or 'none'",
dot_required = "remote_config(): '.' must be an element of the character vector(s) supplied to 'args'",
dot_required = "'.' must be an element of the character vector(s) supplied to 'args'",
function_required = "'.f' must be of type function, not %s",
missing_expression = "missing expression, perhaps wrap in {}?",
missing_url = "at least one URL must be supplied for 'url' or 'n' must be at least 1",
Expand All @@ -102,8 +102,8 @@
not_found = "compute profile '%s' not found",
numeric_n = "'n' must be numeric, did you mean to provide 'url'?",
register_cluster = "this function requires a more recent version of R",
requires_daemons = "mirai_map(): launching one local daemon as none previously set",
requires_local = "ssh_config(): SSH tunnelling requires 'url' hostname to be '127.0.0.1' or 'localhost'",
requires_daemons = "mirai is launching one local daemon for a map operation as none previously set",
requires_local = "SSH tunnelling requires 'url' / 'host' to be '127.0.0.1' or 'localhost'",
single_url = "only one 'url' should be specified",
sync_daemons = "initial sync with daemon(s) timed out after 10s",
sync_dispatcher = "initial sync with dispatcher timed out after 10s",
Expand Down
100 changes: 50 additions & 50 deletions vignettes/mirai.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ To wait for and collect the return value, use the mirai's `[]` method:

``` r
m[]
#> [1] 3.697367 3.579844 4.301144 5.793961 3.385035
#> [1] 5.648591 3.123780 2.562778 4.690994 3.741629
```
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`.

``` r
m
#> < mirai [$data] >
m$data
#> [1] 3.697367 3.579844 4.301144 5.793961 3.385035
#> [1] 5.648591 3.123780 2.562778 4.690994 3.741629
```
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:

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

m <- mirai(.expr = expr, .args = args)
m[]
#> [1] 3.034147 4.392310 3.835027 3.202216 6.234705
#> [1] 2.931940 3.335757 2.892598 4.746409 3.456988
```

[&laquo; Back to ToC](#table-of-contents)
Expand Down Expand Up @@ -200,12 +200,12 @@ status()
#>
#> $daemons
#> i online instance assigned complete
#> abstract://489e852f635343169bb5b99c 1 1 1 0 0
#> abstract://dbf478f4adf050a82c6b7928 2 1 1 0 0
#> abstract://95a11f4ec803d1b06c620a16 3 1 1 0 0
#> abstract://e265c4ff283f9b726876035a 4 1 1 0 0
#> abstract://03a87473897742b3e8cddff1 5 1 1 0 0
#> abstract://78933fb5a90f908d86b0ef8d 6 1 1 0 0
#> abstract://3cf684be35fec4669598b5d0 1 1 1 0 0
#> abstract://f920b65eaa00743dbf7416a2 2 1 1 0 0
#> abstract://303696995b00f8c9d6160a62 3 1 1 0 0
#> abstract://68b0b6c12596f417f03de18c 4 1 1 0 0
#> abstract://c269e8257df73ce6bfa61168 5 1 1 0 0
#> abstract://339cb15f4b9603b8f9cc9202 6 1 1 0 0
```
The default `dispatcher = "process"` creates a `dispatcher()` background process that connects to individual daemon processes on the local machine. This ensures that tasks are dispatched efficiently on a first-in first-out (FIFO) basis to daemons for processing. Tasks are queued at the dispatcher and sent to a daemon as soon as it can accept the task for immediate execution.

Expand Down Expand Up @@ -237,7 +237,7 @@ status()
#> [1] 6
#>
#> $daemons
#> [1] "abstract://1e1ae0cab600b6625eda829a"
#> [1] "abstract://3fab700e47a348a61065fd24"
```
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.

Expand Down Expand Up @@ -265,11 +265,11 @@ m <- mirai(capture.output(str(con)))
m[]
#> [1] "Formal class 'SQLiteConnection' [package \"RSQLite\"] with 8 slots"
#> [2] " ..@ ptr :<externalptr> "
#> [3] " ..@ dbname : chr \"/tmp/RtmpU3kmYO/file44b9382476ab\""
#> [3] " ..@ dbname : chr \"/tmp/RtmpQkiLoR/file315e24274ec8\""
#> [4] " ..@ loadable.extensions: logi TRUE"
#> [5] " ..@ flags : int 70"
#> [6] " ..@ vfs : chr \"\""
#> [7] " ..@ ref :<environment: 0x55c0ae825c48> "
#> [7] " ..@ ref :<environment: 0x591cdf5fda58> "
#> [8] " ..@ bigint : chr \"integer64\""
#> [9] " ..@ extended_types : logi FALSE"
```
Expand Down Expand Up @@ -370,7 +370,7 @@ status()
#> [1] 0
#>
#> $daemons
#> [1] "tcp://hostname:46627"
#> [1] "tcp://hostname:40233"
```
The number of daemons connecting to the host URL is not limited and network resources may be added or removed at any time, with tasks automatically distributed to all connected daemons.

Expand Down Expand Up @@ -461,10 +461,10 @@ daemons(n = 2, url = host_url())
#> [1] 2
launch_remote(1:2)
#> [1]
#> Rscript -e 'mirai::daemon("tcp://hostname:41297",rs=c(10407,1856629192,683105577,1203351254,-1939349665,-1796951532,-1975411195))'
#> Rscript -e 'mirai::daemon("tcp://hostname:41441",rs=c(10407,-1087468743,9462182,708419567,1563637092,1897649429,-768560430))'
#>
#> [2]
#> Rscript -e 'mirai::daemon("tcp://hostname:33309",rs=c(10407,-1633652778,-939033965,-212196445,273938955,-576609069,-1894673157))'
#> Rscript -e 'mirai::daemon("tcp://hostname:40105",rs=c(10407,1995764642,483910581,1338681724,-1453756863,229312716,620309592))'
daemons(0)
#> [1] 0
```
Expand All @@ -491,37 +491,37 @@ The generated self-signed certificate is available via `launch_remote()`. This f
``` r
launch_remote(1)
#> [1]
#> Rscript -e 'mirai::daemon("wss://hostname:39167/1",tls=c("-----BEGIN CERTIFICATE-----
#> Rscript -e 'mirai::daemon("wss://hostname:34529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GyCAS0gRB
#> YaE5poDLfBQUrfQ3KQlK8LPerNGSq1Fe7engjO8DluydeGb0IAaJ0YNO9zsMr9h/
#> uK36o0CX0fQzhrWatXkH/e/stJ7s0f4HTsMmomZPLJy2BDgp8E11CmrhFzHmqoAE
#> 4Fuzv+7kPs/sWOCiBDZJkt2k9LBi2gVu19lTe4yTIN98iUyN5Ff3Q7y4T98uiHvW
#> DJJ8s8/myalP4/qL3UpWxIZraFR+UVTkr/IbPUqEMH/pORN2yveMc09Z+w==
#> -----END CERTIFICATE-----
#> ",""),rs=c(10407,-687431017,690544108,-420826627,-2030608230,77213011,-1323924872))'
#> ",""),rs=c(10407,-1054001662,854874523,-1881956320,-1950819935,531919598,4464279))'
```
The printed value may be deployed directly on a remote machine.

Expand Down Expand Up @@ -753,10 +753,10 @@ daemons(4)
vec <- c(1, 1, 4, 4, 1, 1, 1, 1)
system.time(mirai_map(vec, Sys.sleep)[])
#> user system elapsed
#> 0.004 0.004 4.006
#> 0.005 0.003 4.008
system.time(parLapply(cl, vec, Sys.sleep))
#> user system elapsed
#> 0.009 0.007 8.011
#> 0.010 0.004 8.012
```
`.args` is used to specify further constant arguments to `.f` - the 'mean' and 'sd' in the example below:

Expand All @@ -766,13 +766,13 @@ with(
mirai_map(1:3, rnorm, .args = list(mean = 20, sd = 2))[]
)
#> [[1]]
#> [1] 21.3957
#> [1] 20.54342
#>
#> [[2]]
#> [1] 18.95260 20.25628
#> [1] 17.98820 17.88564
#>
#> [[3]]
#> [1] 22.08272 19.25541 19.62921
#> [1] 20.15189 21.43710 23.64799
```
Use `...` to further specify objects referenced but not defined in `.f` - the 'do' in the anonymous function below:

Expand All @@ -782,18 +782,18 @@ ml <- mirai_map(
function(x) do(x, as.logical(x %% 2)),
do = nanonext::random
)
#> Warning: mirai_map(): launching one local daemon as none previously set
#> Warning: mirai is launching one local daemon for a map operation as none previously set
ml
#> < mirai map [2/3] >
ml[]
#> $a
#> [1] "d6"
#> [1] "33"
#>
#> $b
#> [1] cd 52
#> [1] 0b 81
#>
#> $c
#> [1] "539f47"
#> [1] "a51326"
```
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.

Expand Down

0 comments on commit 4e5203f

Please sign in to comment.