Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no progress bar with backend = NULL #42

Open
MaximilianPi opened this issue Aug 30, 2023 · 1 comment
Open

no progress bar with backend = NULL #42

MaximilianPi opened this issue Aug 30, 2023 · 1 comment
Labels
feature New feature or request not planned This issue or request is not going to be worked on

Comments

@MaximilianPi
Copy link

Hi @mihaiconstantin

thanks for the great package. Is it intended that there's no progress bar for backend = NULL?:

parabar::configure_bar(type = "modern", format = "[:bar] :percent :eta", width = getOption("width")/2)
results <- parabar::par_sapply(NULL, 1:100, function(x) {
  # Sleep a bit.
  Sys.sleep(0.01)
  
  # Compute and return.
  x + 1
})
@mihaiconstantin
Copy link
Owner

Hi @MaximilianPi,

Thanks for reaching out.

Indeed, with backend = NULL, the execution is sequential (i.e., base::sapply in this case), which does not have any progress-tracking or other capabilities, as seen below:

parabar/R/UserApiConsumer.R

Lines 181 to 198 in 2844b4d

sapply = function(backend, x, fun, ...) {
# Prepare the sequential operation.
sequential <- bquote(
do.call(
base::sapply, c(list(X = .(x), FUN = .(fun)), .(list(...)))
)
)
# Prepare the parallel operation.
parallel <- bquote(
do.call(
context$sapply, c(list(x = .(x), fun = .(fun)), .(list(...)))
)
)
# Execute the `sapply` operation accordingly and return the results.
private$.execute(backend, parallel, sequential)
},

Now, it is straightforward to add progress tracking in this case, but I think it is better suited for the task function itself rather than parabar::par_sapply. At that time, the rationale behind this decision was to keep the architecture clean.

However, I am considering extending the contexts (e.g., ProgressTrackingContext) to also provide the corresponding behavior implementation for sequential operations.

For now, you can still achieve the same using the developer API as follows:

# Instantiate a `ModernBar`.
bar <- ModernBar$new()

# Create the bar.
bar$create(total = 100, initial = 0, format = "[:bar] :percent :eta", width = getOption("width") / 2)

# Run the task sequentially.
results <- parabar::par_sapply(NULL, 1:100, function(x) {
    # Update the progress bar.
    bar$update(x)

    # Sleep a bit.
    Sys.sleep(0.01)

    # Compute and return.
    x + 1
})

# Terminate the bar.
bar$terminate()

I hope this helps.

@mihaiconstantin mihaiconstantin self-assigned this Sep 6, 2023
@mihaiconstantin mihaiconstantin added the feature New feature or request label Sep 6, 2023
@github-project-automation github-project-automation bot moved this to Backlog in parabar Sep 6, 2023
@mihaiconstantin mihaiconstantin moved this from Backlog to Todo in parabar Sep 6, 2023
@mihaiconstantin mihaiconstantin moved this from Todo to Backlog in parabar Jan 30, 2024
@mihaiconstantin mihaiconstantin moved this from Backlog to Later in parabar Feb 5, 2024
@mihaiconstantin mihaiconstantin added the not planned This issue or request is not going to be worked on label Oct 16, 2024
@mihaiconstantin mihaiconstantin removed their assignment Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request not planned This issue or request is not going to be worked on
Projects
Status: Later
Development

No branches or pull requests

2 participants