メインコンテンツへスキップ
ionworks-api Python パッケージは、パイプラインの実行と管理のための client.pipeline を提供します。インストールと認証については Python API クライアント を参照してください。

パイプラインの送信

import ionworks_schema as iws
from ionworks import Ionworks

# 環境変数 IONWORKS_API_KEY と IONWORKS_PROJECT_ID を読み込みます
client = Ionworks()

pipeline = iws.Pipeline(
    {
        "known": iws.direct_entries.DirectEntry(
            parameters={"Ambient temperature [K]": 298.15},
        ),
        "Q_pos": iws.calculations.ElectrodeCapacity(electrode="positive"),
    },
    name="Capacity pipeline",
)

submission = client.pipeline.create(pipeline)
print(f"Pipeline ID: {submission.id}")
print(f"Status: {submission.status}")
client.pipeline.create()iws.Pipeline インスタンスでも .to_config() が返す dict でも受け取れます。スキーマインスタンスは送信前にローカルで検証されるため、形状エラーは即座に表面化します。

送信メタデータの上書き

create() は、スキーマに含まれる値を上書きするための project_idnamedescriptionoptions を kwargs として受け付けます。
submission = client.pipeline.create(
    pipeline,
    project_id="your-project-id",
    name="Custom run name",
    options={"live_progress_updates": True},
)
project_id を省略した場合、クライアントは Ionworks(...) のデフォルト、または環境変数 IONWORKS_PROJECT_ID にフォールバックします。

完了待ち

submission = client.pipeline.wait_for_completion(
    submission.id,
    timeout=600,        # 秒 (デフォルト: 600)
    poll_interval=2,    # ポーリング間隔 [秒] (デフォルト: 2)
    verbose=True,       # ステータス出力 (デフォルト: True)
)
パイプラインが失敗した際に例外を発生させず失敗レスポンスを返すには、raise_on_failure=False を指定します。

結果の取得

result = client.pipeline.result(submission.id)

# パイプラインが生成した最終パラメータ値
print(result.result)

# Pipeline 内で使用した要素名をキーとする出力
print(result.element_results["Q_pos"])
result.element_results のキーは iws.Pipeline(elements=...) に渡したキーと対応します。

要素のメタデータ

一部の要素(特に Validation)は element_results に含まれない追加メタデータを書き込みます。それらは次で取得できます。
metadata = client.pipeline.get_element_metadata(submission.id, "validate")

パイプライン一覧

# Ionworks(...) のデフォルトまたは IONWORKS_PROJECT_ID を使用
pipelines = client.pipeline.list()

# 1 回の呼び出しだけプロジェクトを上書き
pipelines = client.pipeline.list(project_id="other-project-id")

# 件数を制限
pipelines = client.pipeline.list(limit=10)

単一送信の取得

submission = client.pipeline.get(submission.id)
print(submission.status)  # "pending", "running", "completed", "failed"

エンドツーエンドの例

import ionworks_schema as iws
from ionworks import Ionworks

client = Ionworks()

pipeline = iws.Pipeline(
    {
        "known": iws.direct_entries.DirectEntry(
            parameters={"Ambient temperature [K]": 298.15},
        ),
        "fit": iws.DataFit(
            objectives={
                "1C": iws.objectives.CurrentDriven(
                    data_input="file:examples/data/chen_synthetic_1C/time_series.csv",
                    options={"model": {"type": "SPMe"}},
                ),
            },
            parameters={
                "Negative particle diffusivity [m2.s-1]": iws.Parameter(
                    "Negative particle diffusivity [m2.s-1]",
                    initial_value=2e-14,
                    bounds=(1e-14, 1e-13),
                ),
            },
            cost=iws.costs.RMSE(),
            optimizer=iws.optimizers.DifferentialEvolution(),
        ),
    },
    name="SPMe diffusivity fit",
)

submission = client.pipeline.create(pipeline)
client.pipeline.wait_for_completion(submission.id)

result = client.pipeline.result(submission.id)
print(result.element_results["fit"])
より多くのエンドツーエンド例(エントリのみ、計算のみ、データフィット、検証)は SDK リポジトリの packages/ionworks-api/examples/pipeline/ を参照してください。