Giter Club home page Giter Club logo

observablepmap.jl's Introduction

ObservablePmap

distributed map returning an observable for following worker progress

Directly setting worker status message – opmap

The opmap function is a wrapper around pmap which allows workers to report their status. The function passed to opmap takes as its first argument a callback setmessage that can be used to set a status message for the current worker. Unlike pmap, the mapping is performed asynchronously. opmap returns an Observable summary string of worker statuses, and the Task performing the mapping.

Example

Running some fake work and viewing worker state in IJulia or Juno plot pane using HTML:

using Distributed
addprocs(2)

@everywhere using ObservablePmap
using CSSUtil: vbox

obs, task = opmap(1:5; schedule_now=false, on_error=identity) do setmessage, x
    setmessage("Initializing...")
    sleep(1)
    n = rand(2:10)
    for i=1:n
        setmessage("Fooing $x-bars ($i/$n) ")
        x==3 && error("Error at $i")
        sleep(rand())
    end
    setmessage("All $x-bars successfully fooed.")
end

html = map(x -> HTML("<pre>$x</pre>"), obs)
schedule(task)
vbox(html)  # not necessary on IJulia

Here's what the output looks like in Juno's plot pane:

Observing log messages – ologpmap

When using ologpmap, log messages produced by workers are used as their status message. Accordingly, the function argument to ologpmap does not take an additional setmessage argument. By default, log messages in workers are processed by a Base.CoreLogging.SimpleLogger, and its output is used as the status message. The logger_f keyword argument to ologpmap can be used to specify a different logger: specifically, logger_f(io) should produce a logger writing log messages to io.

Example

This example uses ProgressLogging.jl and TerminalLoggers.jl to show progress bars.

using Distributed
addprocs(2)
@everywhere using ObservablePmap
@everywhere using ProgressLogging
@everywhere using TerminalLoggers
using CSSUtil: vbox

summ, task = ologpmap( 'a':'e', 2:2:10; logger_f=TerminalLogger ) do c, x
    @withprogress name="Processing '$c'" for i=1:x
        sleep(rand())
        @logprogress i/x
    end
    @info "finished '$c'."
    x
end

html = map(x -> HTML("<pre>$x</pre>"), summ)
vbox(html)

observablepmap.jl's People

Contributors

yha avatar

Stargazers

 avatar  avatar

Watchers

 avatar

observablepmap.jl's Issues

TagBot trigger issue

This issue is used to trigger TagBot; feel free to unsubscribe.

If you haven't already, you should update your TagBot.yml to include issue comment triggers.
Please see this post on Discourse for instructions and more details.

If you'd like for me to do this for you, comment TagBot fix on this issue.
I'll open a PR within a few hours, please be patient!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.