Port a bootstrap confidence interval computation to Modal using a local orchestrator that fans out bootstrap iterations to parallel workers
harbor run -t vmax-modal/modal-port-v1-patched-xr-local-entry-bootstrap-ciharbor download vmax-modal/modal-port-v1-patched-xr-local-entry-bootstrap-ciYou are given an xarray-based workflow that estimates a bootstrap confidence interval for the mean of a 1D dataset. Your task is to port this workflow to Modal so that the bootstrap iterations are distributed across parallel remote workers, with a local orchestrator coordinating the fan-out and computing the final confidence interval from the collected bootstrap means.
xr.DataArray with n_obs observations sampled from a standard normal distribution using a seeded RNG.n_bootstrap iterations (indexed i = 0, 1, ..., n_bootstrap - 1), generate a resample of size n_obs with replacement using a deterministic seed (seed + i + 1), compute the mean of the resample, and collect it.q (lower bound) and 1 - q (upper bound) to form the confidence interval.Each test case is a dictionary with the following keys:
seed (int): Random seed for generating the original observations.n_obs (int): Number of observations in the dataset.n_bootstrap (int): Number of bootstrap resamples to perform.q (float): Lower quantile for the confidence interval (e.g., 0.025 for 95% CI).A dictionary with three float-valued keys:
{
"ci_lower": <float>,
"ci_upper": <float>,
"mean": <float>
}
Where ci_lower = quantile(q) and ci_upper = quantile(1 - q) of the bootstrap means, and mean is the mean of the original observations.
Your solution must be structured as follows:
Write a local entrypoint function (plain Python, not a Modal Function) that:
seed, n_obs, n_bootstrap, q).n_bootstrap iterations into at least 4 batches.ci_lower = quantile(q) and ci_upper = quantile(1 - q) from the combined means.mean from the original observations (generated locally or via a remote call).At least one Modal Function should:
start_i and end_i), plus seed, n_obs.i in the batch, generate seed + i + 1 as the resample RNG seed, draw n_obs integer indices uniformly at random from [0, n_obs), index into the original data using those indices, and compute the mean.Your Modal app's container image must include numpy and xarray so that DataArray operations work correctly.
Your solution must satisfy these behavioral requirements:
ci_lower, ci_upper, and mean must match the reference implementation to within absolute and relative tolerance of 1e-6. This requires using the exact same seeding scheme (seed + i + 1 for iteration i) and the same RNG API (np.random.default_rng).np.random.default_rng(seed).standard_normal(n_obs). You must reproduce this exactly, whether by generating locally and passing the data to workers, or by regenerating inside the remote function.np.random.default_rng(seed + i + 1).integers(0, n_obs, size=n_obs) to draw replacement indices. This must be reproduced exactly.xr.DataArray.quantile(q) over the bootstrap dimension, which is equivalent to numpy's default linear interpolation quantile.mean field is the plain mean of the original n_obs observations, not a bootstrap mean.Write the solution in /app/solution/modal_app.py. Define a Modal application
object named app and expose a callable named run_case that accepts one case
dictionary and returns a JSON-serializable result matching the original
workflow.
The finalized task workspace is copied into /app when the sandbox starts.
Source files from environment/workspace are available at paths such as
/app/workflow.py, /app/original_workflow.py, /app/original.py, or other
task-specific filenames.
Implement run_case as a local orchestrator: a plain Python function (not itself a Modal Function) that the harness calls directly and that dispatches work to one or more Modal Functions via .remote(...), .map(...), or .starmap(...).
The solution must also use: