Communitygithub.com

G1Joshi/Agent-Skills

Dask分散コンピューティング支援のエキスパート。Dask DataFrame、Array、Futures、クラスタスケーリングに対応。単一マシンやマルチノードクラスタでpandasでは処理できない大規模データセットの分析に最適です。

Agent-Skills とは?

このスキルは、Daskを使用した分散コンピューティングを支援するエキスパートエージェントです。DaskはPythonをスケーリングし、PandasやNumPyに似たAPIを提供しながら、クラスタ上で大規模データ処理を可能にします。特に、メモリに収まらないテーブルデータ(10GB〜1TB)の処理、カスタムPythonワークフローの並列化、分散機械学習、そしてNumPy/Pandasのスケーリングに役立ちます。このエージェントは、Dask DataFrameを使った遅延評価による大規模Parquetファイルの集計、`dask.delayed`を使ったカスタムタスクグラフの構築、Dask Arrayによる分散線形代数、そしてDask Distributed Clientを用いた非同期Futuresの活用方法を具体的なコード例とともに提供します。また、Dask Webダッシュボードの活用、適切なチャンクサイズの選択、`persist()`の使用、早期のフィルタリングといったベストプラクティスや、メモリ不足やタスクオーバーヘッドに関するトラブルシューティングも網羅しており、開発者がDaskを効率的に使いこなせるように導きます。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/G1Joshi/Agent-Skills/tree/HEAD/skills/ai-ml/dask

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

Dask

DaskはPythonをスケーリングします。Pandas/NumPyのように見えますが、クラスタ上で動作します。2025年のアップデートでは、高性能シャッフルとGPU統合に焦点が当てられています。

使用するタイミング

  • メモリを超えるテーブル計算: 単一マシンまたはマルチノードクラスタで10GB〜1TBのCSV/Parquetデータセットを処理する場合。
  • カスタムPythonワークフローの並列化: dask.delayedを使用して、任意のPythonループやタスクグラフを並列化する場合。
  • 分散機械学習: 分散ワーカーノード間でScikit-learn、XGBoost、LightGBMと連携する場合。
  • NumPyとPandasのスケーリング: アウトオブコアの配列およびDataFrame計算のための、おなじみのAPIをそのまま利用する場合。

クイックスタート

import dask.dataframe as dd

# マルチギガバイトの分割CSVファイルを遅延読み込み
df = dd.read_csv('data/transactions_*.csv')

# すべてのCPUコアで並列に集計統計を計算
result = df.groupby('category').amount.mean().compute()
print(result)

コアコンセプト

Dask DataFrameによるアウトオブコア処理

分割されたParquetファイルを遅延読み込みし、集計を遅延評価で計算します。

import dask.dataframe as dd
from dask.distributed import Client

# ローカルの分散クラスタを初期化
client = Client(n_workers=4, threads_per_worker=2, memory_limit='4GB')
print(f"DaskダッシュボードのURL: {client.dashboard_link}")

# マルチファイルデータセットを遅延読み込み
df = dd.read_parquet(
    's3://analytics-bucket/transactions/*.parquet',
    columns=['customer_id', 'amount', 'status', 'country'],
    engine='pyarrow'
)

# 計算グラフを遅延構築
filtered = df[df['status'] == 'completed']
metrics = filtered.groupby('country')['amount'].agg(['mean', 'sum', 'count'])

# グラフを実行し、具体的なPandas DataFrameを返す
result_df = metrics.compute()
print(result_df)

dask.delayedによるカスタムタスクグラフ

独立した関数実行の並列化:

from dask import delayed, compute
import time

@delayed
def fetch_api_data(endpoint: str) -> dict:
    time.sleep(0.5) # I/Oをシミュレート
    return {'endpoint': endpoint, 'status': 200, 'items': [1, 2, 3]}

@delayed
def transform_payload(data: dict) -> int:
    return sum(data['items'])

@delayed
def aggregate_totals(totals: list[int]) -> int:
    return sum(totals)

# 依存関係DAGを構築
endpoints = ['users', 'orders', 'inventory', 'payments']
fetched = [fetch_api_data(ep) for ep in endpoints]
transformed = [transform_payload(f) for f in fetched]
final_total = aggregate_totals(transformed)

# すべてのタスクをクラスタ上で並列実行
total_result = final_total.compute()
print("総計:", total_result)

Dask Arrayによる分散線形代数

巨大な多次元配列を操作する:

import dask.array as da

# 50,000 x 50,000 の配列を5,000 x 5,000のチャンクに分割して作成
x = da.random.normal(10, 0.1, size=(50000, 50000), chunks=(5000, 5000))

# 計算を遅延実行
y = x + x.T
z = y[::2, ::2].mean(axis=0)

# 結果を計算
result = z.compute()
print("計算された配列の平均形状:", result.shape)

一般的なパターン

不規則な並列タスクグラフのための分散Futures

問題: DataFrame/Arrayの行/列構造にうまく適合しないカスタム並列計算。

解決策: 非同期FuturesとともにDask Distributed Clientを使用する:

from dask.distributed import Client

client = Client(n_workers=4, threads_per_worker=2)

def train_partition(part_id: int):
    # ローカルのサブモデルを訓練
    return f"モデル {part_id} を訓練完了"

futures = [client.submit(train_partition, i) for i in range(10)]
results = client.gather(futures)
print(results)

ベストプラクティス (2026)

  • 実行する Dask Webダッシュボード(通常ポート8787)を確認して、メモリ負荷、タスクストリーム、ボトルネックを監視する。
  • 実行する 最適な並列効率のために、メモリ内で100MB〜300MBのチャンクサイズを選択する。
  • 実行する 同じ変換済みデータを繰り返しクエリする場合は、中間DataFrameを永続化する(df = df.persist())。
  • 実行する カラムプロジェクションとプッシュダウン述語を使用して、早期にカラムと行をフィルタリングする。
  • 避ける ループ内で.compute()を呼び出さない。完全なタスクグラフを構築してから一度だけcompute()を呼び出す。
  • 避ける データがRAMに収まる場合はDaskを使用しない。インメモリタスクではネイティブのPandasやPolarsの方がはるかに高速。
  • 避ける 数百万の小さな遅延タスクを作成しない。過剰なタスクオーバーヘッドがスケジューラのパフォーマンスを低下させる。

トラブルシューティング

エラー原因解決策
KilledWorker: Worker exceeded 95% memory budgetタスクパーティションが大きすぎて、計算時にワーカーRAMに収まらない。パーティション数を増やす: df.repartition(npartitions=100)。
UserWarning: Sending large object to workers大きなNumPy配列やDataFrameが関数の直接引数として渡されている。タスクを送信する前に、client.scatter(data)でデータを一度だけ分散させる。
Slow compute: Too many tiny tasks数千のマイクロパーティションがタスクスケジューリングのオーバーヘッドを引き起こす。repartition(partition_size="100MB")を使用して小さなパーティションを統合する。

参考文献

Individual skills in this repo

This repo contains 11 individual skills — each has its own dedicated page.

G1Joshi/Agent-Skills

Expert dbt (data build tool) assistance covering SQL modeling, Jinja macros, tests, documentation, and semantic layer. Use when building analytics engineering pipelines on BigQuery, Snowflake, or PostgreSQL.

G1Joshi/Agent-Skills

Expert JAX assistance covering Autograd, XLA compilation (`jit`), vectorization (`vmap`), and parallelization (`pmap`). Use when building high-performance numerical computing and cutting-edge deep learning research.

G1Joshi/Agent-Skills

Expert Ray distributed computing assistance covering Ray Core (actors, tasks), Ray Train, Ray Tune, and Ray Serve. Use when scaling Python compute and ML training across multi-node clusters.

G1Joshi/Agent-Skills

Expert Git version control assistance covering branching, interactive rebase, cherry-pick, submodules, worktrees, and conflict resolution. Use when managing source code history and collaboration workflows.

G1Joshi/Agent-Skills

Expert K9s CLI assistance covering terminal Kubernetes cluster navigation, real-time log streaming, port forwarding, and pod debugging. Use when managing and troubleshooting Kubernetes clusters with speed.

G1Joshi/Agent-Skills

Expert SWC assistance covering high-performance Rust-based JavaScript/TypeScript compilation, .swcrc configuration, Jest testing via @swc/jest, and minification. Use when replacing Babel with SWC for faster builds, accelerating test execution, or compiling modern ECMAScript features.

G1Joshi/Agent-Skills

Expert Tig assistance covering text-mode interface for Git, interactive staging, commit graph visualization, diff exploration, and blame navigation. Use when navigating Git commit history in the terminal, staging hunks interactively, browsing file changes, or reviewing revisions.

G1Joshi/Agent-Skills

Expert Vim assistance covering modal editing, .vimrc configuration, registers, macros, search/replace, and plugin management via vim-plug. Use when editing text efficiently in terminal environments, writing Vimscript, recording macros, or configuring core Vim settings.

G1Joshi/Agent-Skills

Expert Zed editor assistance covering high-performance Rust-based text editing, multi-buffer editing, language server protocols (LSP), and AI assistant integrations. Use when configuring Zed settings.json, setting up language extensions, collaborating in real-time channels, or optimizing editor startup speed.

G1Joshi/Agent-Skills

Expert Zsh assistance covering shell customization, Oh My Zsh plugins, Zinit plugin manager, prompt engineering (Starship/Powerlevel10k), and shell scripting. Use when configuring .zshrc, writing Zsh automation scripts, optimizing shell startup time, or configuring tab-completion.

G1Joshi/Agent-Skills

Expert [skill-name] assistance covering [feature 1], [feature 2], and [feature 3]. Use when [working with X], [debugging Y], or [implementing Z].

関連スキル