QCSC Prefect API Reference¶
This page is generated from Python docstrings in the core qcsc-prefect
packages. Native Qiskit primitives are documented separately in
Native Qiskit API.
Core Models¶
qcsc_prefect_core.models.execution_profile.ExecutionProfile
dataclass
¶
ExecutionProfile(
command_key: str,
num_nodes: int,
mpiprocs: int | None = None,
ompthreads: int | None = None,
walltime: str | None = None,
launcher: Launcher = "single",
mpi_options: list[str] = list(),
modules: list[str] = list(),
pre_commands: list[str] = list(),
environments: dict[str, str] = dict(),
arguments: list[str] = list(),
)
Minimal execution profile for Miyabi PBS template.
NOTE: - This is intentionally "template-driven" MVP. - Later you can evolve this into common+overrides and canonicalization.
Prefect Blocks¶
qcsc_prefect_blocks.common.blocks.CommandBlock ¶
Bases: Block
Command definition (what to run). Common for all HPC systems.
qcsc_prefect_blocks.common.blocks.ExecutionProfileBlock ¶
Bases: Block
Execution baseline (how to run). Common for all HPC systems.
qcsc_prefect_blocks.common.blocks.HPCProfileBlock ¶
Bases: Block
HPC target-specific profile (where to submit). Supports Miyabi, Fugaku, and Slurm.
Block-Based Execution¶
qcsc_prefect_executor.from_blocks.SubmissionTarget
dataclass
¶
SubmissionTarget(
hpc_target: str, queue_name: str, project: str
)
Scheduler routing information resolved from Prefect blocks.
Attributes:
| Name | Type | Description |
|---|---|---|
hpc_target |
str
|
Scheduler backend name, such as |
queue_name |
str
|
Queue, partition, or resource-group name selected for the execution profile's resource class. |
project |
str
|
Project, group, or account name selected for the resource class. This can be empty for scheduler targets that do not require an account. |
qcsc_prefect_executor.from_blocks.resolve_hpc_target
async
¶
resolve_hpc_target(*, hpc_profile_block_name: str) -> str
Load an HPCProfileBlock and return its scheduler target name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hpc_profile_block_name
|
str
|
Prefect block document name for
|
required |
Returns:
| Type | Description |
|---|---|
str
|
The configured |
str
|
|
qcsc_prefect_executor.from_blocks.resolve_submission_target
async
¶
resolve_submission_target(
*,
hpc_profile_block_name: str,
execution_profile_block_name: str,
) -> SubmissionTarget
Resolve scheduler routing from block names without submitting a job.
This helper is useful when a flow needs to inspect the target queue or
project before it creates scheduler-specific filenames or logs. It loads
the HPCProfileBlock and ExecutionProfileBlock and chooses CPU or
GPU queue/project fields from the execution profile's resource_class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hpc_profile_block_name
|
str
|
Prefect block document name for target-specific scheduler settings. |
required |
execution_profile_block_name
|
str
|
Prefect block document name for scheduler-independent execution settings. |
required |
Returns:
| Type | Description |
|---|---|
SubmissionTarget
|
Resolved scheduler target, queue/partition/resource group, and |
SubmissionTarget
|
project/account values. |
qcsc_prefect_executor.from_blocks.build_scheduler_script_filename ¶
build_scheduler_script_filename(
script_stem: str, hpc_target: str
) -> str
Build a scheduler-specific script filename from a logical stem.
Existing scheduler suffixes are replaced, while names without a known
scheduler suffix receive the target suffix appended. For example,
"batch" becomes "batch.pbs" for Miyabi and "batch.slurm" for
Slurm; "batch.pbs" becomes "batch.pjm" for Fugaku.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
script_stem
|
str
|
Logical script name or existing scheduler script filename. |
required |
hpc_target
|
str
|
Scheduler target name. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Script filename with the suffix required by the scheduler target. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If |
qcsc_prefect_executor.from_blocks.resolve_scheduler_script_filename
async
¶
resolve_scheduler_script_filename(
*, script_stem: str, hpc_profile_block_name: str
) -> str
Resolve scheduler target from blocks and return a matching filename.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
script_stem
|
str
|
Logical script name or existing scheduler script filename. |
required |
hpc_profile_block_name
|
str
|
Prefect block document name used to determine the scheduler target. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Scheduler-specific script filename. |
qcsc_prefect_executor.from_blocks.run_job_from_blocks
async
¶
run_job_from_blocks(
*,
command_block_name: str,
execution_profile_block_name: str,
hpc_profile_block_name: str,
work_dir: Path,
script_filename: str,
user_args: list[str] | None = None,
watch_poll_interval: float = 10.0,
timeout_seconds: float | None = None,
metrics_artifact_key: str = "hpc-job-metrics",
fugaku_job_name: str | None = None,
execution_profile_overrides: dict[str, Any]
| None = None,
) -> Any
Resolve Prefect blocks and execute a job on the configured HPC target.
This is the main block-driven entrypoint for workflow authors. It loads the command, execution profile, and HPC profile blocks; converts them into the internal runtime models; creates the target-specific scheduler request; and dispatches to the Miyabi, Fugaku, or Slurm executor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command_block_name
|
str
|
Prefect block document name for the command to run. |
required |
execution_profile_block_name
|
str
|
Prefect block document name describing resources, launcher, environment, and default execution behavior. |
required |
hpc_profile_block_name
|
str
|
Prefect block document name describing the scheduler target, queues, projects, and executable mapping. |
required |
work_dir
|
Path
|
Working directory where scheduler scripts and job outputs are created. |
required |
script_filename
|
str
|
Logical or scheduler-specific script filename. The suffix is normalized for the resolved target. |
required |
user_args
|
list[str] | None
|
Optional extra command-line arguments appended after the command block's default arguments. |
None
|
watch_poll_interval
|
float
|
Seconds to wait between scheduler status polls. |
10.0
|
timeout_seconds
|
float | None
|
Optional maximum wait time for terminal job status. |
None
|
metrics_artifact_key
|
str
|
Prefect artifact key used for job metrics. |
'hpc-job-metrics'
|
fugaku_job_name
|
str | None
|
Optional Fugaku PJM job name. When omitted, a safe name is derived from the command name. |
None
|
execution_profile_overrides
|
dict[str, Any] | None
|
Optional runtime overrides for selected
execution profile fields, such as |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
A target-specific result object: |
Any
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the command and execution profile blocks refer to different command names, if a required project/group is missing, or if unsupported execution profile override keys are provided. |
KeyError
|
If the command's executable key is missing from the HPC profile's executable map. |
NotImplementedError
|
If the resolved |
Miyabi API¶
qcsc_prefect_adapters.miyabi.builder.MiyabiJobRequest
dataclass
¶
MiyabiJobRequest(
queue_name: str, project: str, executable: str
)
Target-specific request fields required to build a Miyabi PBS job.
Attributes:
| Name | Type | Description |
|---|---|---|
queue_name |
str
|
Miyabi PBS queue name, for example |
project |
str
|
Miyabi group/project name passed to the PBS template. |
executable |
str
|
Absolute or scheduler-visible command path to execute. |
qcsc_prefect_adapters.miyabi.builder.to_miyabi_template_kwargs ¶
to_miyabi_template_kwargs(
*, exec_profile: ExecutionProfile, req: MiyabiJobRequest
) -> dict
Build template variables for the Miyabi PBS script.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exec_profile
|
ExecutionProfile
|
Scheduler-independent execution profile. |
required |
req
|
MiyabiJobRequest
|
Miyabi-specific scheduler request fields. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
A dictionary that can be passed to the Miyabi Jinja template. |
qcsc_prefect_adapters.miyabi.builder.render_script ¶
render_script(
*,
work_dir: Path,
exec_profile: ExecutionProfile,
req: MiyabiJobRequest,
) -> str
Render a Miyabi job script text from the configured Jinja template.
.. note::
The template file is configured by module constant _TEMPLATE and
is expected to be a .j2 file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
work_dir
|
Path
|
Working directory injected into the template. |
required |
exec_profile
|
ExecutionProfile
|
Scheduler-independent execution profile. |
required |
req
|
MiyabiJobRequest
|
Miyabi-specific scheduler request fields. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Rendered PBS script text. |
qcsc_prefect_adapters.miyabi.builder.write_script_file ¶
write_script_file(
*, work_dir: Path, filename: str, text: str
) -> Path
Write a rendered job script into the work directory.
.. note::
This function is expected to be called inside
qcsc_prefect_executor.miyabi.run.run_miyabi_job.
Workflow authors normally do not need to call it directly.
.. note::
The text argument is expected to come from render_script,
which renders the .j2 template specified by _TEMPLATE.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
work_dir
|
Path
|
Base working directory where the script file is created. |
required |
filename
|
str
|
Script file name (for example |
required |
text
|
str
|
Rendered script text. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Absolute path to the created job script file. |
qcsc_prefect_adapters.miyabi.runtime.SubmitResult
dataclass
¶
SubmitResult(job_id: str, raw_output: str)
Submission result returned after PBS accepts a batch script.
Attributes:
| Name | Type | Description |
|---|---|---|
job_id |
str
|
PBS job id parsed from |
raw_output |
str
|
Raw, stripped stdout emitted by |
qcsc_prefect_adapters.miyabi.runtime.MiyabiPBSRuntime ¶
Async runtime wrapper for Miyabi PBS scheduler commands.
The runtime maps to the core PBS commands used on Miyabi:
qsub for submission, qstat -fH for completed-job status, and
qdel for cancellation. Workflow code usually calls
qcsc_prefect_executor.miyabi.run.run_miyabi_job or
qcsc_prefect_executor.from_blocks.run_job_from_blocks instead.
submit
async
¶
submit(
script_path: Path, *, cwd: Path | None = None
) -> SubmitResult
Submit a PBS script with qsub.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
script_path
|
Path
|
Path to the PBS script file. |
required |
cwd
|
Path | None
|
Optional working directory for |
None
|
Returns:
| Type | Description |
|---|---|
SubmitResult
|
Parsed submission result including job id and raw output. |
Raises:
| Type | Description |
|---|---|
SubmitError
|
If submission fails or job id cannot be parsed. |
wait_final_status
async
¶
wait_final_status(
job_id: str,
*,
watch_poll_interval: float = 10.0,
timeout_seconds: float | None = None,
) -> dict[str, Any]
Wait until PBS reports the job in the finished-job list.
qstat -fH exposes completed jobs on Miyabi. This method polls that
view, parses PBS key = value records, and preserves continuation
lines in the returned payload.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_id
|
str
|
PBS job id to watch. |
required |
watch_poll_interval
|
float
|
Seconds to wait between |
10.0
|
timeout_seconds
|
float | None
|
Optional maximum wait time. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Parsed final PBS status dictionary. |
Raises:
| Type | Description |
|---|---|
WaitTimeout
|
If |
RuntimeError
|
If an underlying |
cancel
async
¶
cancel(job_id: str) -> None
Cancel a PBS job using qdel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_id
|
str
|
Target PBS job id. |
required |
Raises:
| Type | Description |
|---|---|
CancelError
|
If cancellation fails. |
qcsc_prefect_executor.miyabi.run.MiyabiRunResult
dataclass
¶
MiyabiRunResult(
job_id: str,
exit_status: int,
job_status: dict[str, Any],
)
Normalized result returned by run_miyabi_job.
Attributes:
| Name | Type | Description |
|---|---|---|
job_id |
str
|
PBS job id returned by |
exit_status |
int
|
Integer PBS |
job_status |
dict[str, Any]
|
Parsed final PBS status dictionary from |
qcsc_prefect_executor.miyabi.run.run_miyabi_job
async
¶
run_miyabi_job(
*,
work_dir: Path,
script_filename: str,
exec_profile: ExecutionProfile,
req: MiyabiJobRequest,
watch_poll_interval: float = 10.0,
timeout_seconds: float | None = None,
metrics_artifact_key: str = "miyabi-job-metrics",
) -> MiyabiRunResult
Execute a Miyabi job end-to-end from runtime models.
.. note:: This function is the high-level executor entrypoint. It internally renders a script, submits it, waits for final status, captures logs, and publishes a metrics artifact.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
work_dir
|
Path
|
Working directory where scripts and job outputs are written. |
required |
script_filename
|
str
|
Job script filename to create in |
required |
exec_profile
|
ExecutionProfile
|
Scheduler-independent execution profile. |
required |
req
|
MiyabiJobRequest
|
Miyabi-specific scheduler request fields. |
required |
watch_poll_interval
|
float
|
Poll interval in seconds for job status checks. |
10.0
|
timeout_seconds
|
float | None
|
Optional timeout for waiting final status. |
None
|
metrics_artifact_key
|
str
|
Prefect artifact key for job metrics table. |
'miyabi-job-metrics'
|
Returns:
| Type | Description |
|---|---|
MiyabiRunResult
|
|
MiyabiRunResult
|
scheduler status payload. |
qcsc_prefect_executor.miyabi.from_blocks.run_miyabi_job_from_blocks
async
¶
run_miyabi_job_from_blocks(
*,
command_block_name: str,
execution_profile_block_name: str,
hpc_profile_block_name: str,
work_dir: Path,
script_filename: str,
user_args: list[str] | None = None,
watch_poll_interval: float = 10.0,
timeout_seconds: float | None = None,
metrics_artifact_key: str = "miyabi-job-metrics",
) -> MiyabiRunResult
Backward-compatible wrapper around run_job_from_blocks.
Fugaku API¶
qcsc_prefect_adapters.fugaku.builder.FugakuJobRequest
dataclass
¶
FugakuJobRequest(
queue_name: str,
project: str,
executable: str,
job_name: str = "prefect_job",
gfscache: str | None = None,
mpi_options_for_pjm: list[str] | None = None,
spack_modules: list[str] | None = None,
pjm_resources: list[str] | None = None,
)
Target-specific request fields required to build a Fugaku PJM job.
Attributes:
| Name | Type | Description |
|---|---|---|
queue_name |
str
|
Fugaku resource group name. |
project |
str
|
Fugaku group name passed to PJM. |
executable |
str
|
Absolute or scheduler-visible command path to execute. |
job_name |
str
|
PJM job name used for scheduler display and output filenames. |
gfscache |
str | None
|
Optional |
mpi_options_for_pjm |
list[str] | None
|
Optional MPI options emitted as PJM directives. |
spack_modules |
list[str] | None
|
Optional Spack modules loaded by the generated script. |
pjm_resources |
list[str] | None
|
Additional raw |
qcsc_prefect_adapters.fugaku.builder.to_fugaku_template_kwargs ¶
to_fugaku_template_kwargs(
*,
work_dir: Path,
exec_profile: ExecutionProfile,
req: FugakuJobRequest,
script_basename: str = "batch.pjm",
) -> dict
Build template variables for the Fugaku PJM script.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
work_dir
|
Path
|
Base working directory used to derive output paths. |
required |
exec_profile
|
ExecutionProfile
|
Scheduler-independent execution profile. |
required |
req
|
FugakuJobRequest
|
Fugaku-specific scheduler request fields. |
required |
script_basename
|
str
|
Script basename used for output/stat filenames. |
'batch.pjm'
|
Returns:
| Type | Description |
|---|---|
dict
|
A dictionary that can be passed to the Fugaku Jinja template. |
qcsc_prefect_adapters.fugaku.builder.render_script ¶
render_script(
*,
work_dir: Path,
exec_profile: ExecutionProfile,
req: FugakuJobRequest,
script_basename: str = "batch.pjm",
) -> str
Render a Fugaku job script text from the configured Jinja template.
.. note::
The template file is configured by module constant _TEMPLATE and
is expected to be a .j2 file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
work_dir
|
Path
|
Base working directory used in template variables. |
required |
exec_profile
|
ExecutionProfile
|
Scheduler-independent execution profile. |
required |
req
|
FugakuJobRequest
|
Fugaku-specific scheduler request fields. |
required |
script_basename
|
str
|
Script basename used for output/stat filenames. |
'batch.pjm'
|
Returns:
| Type | Description |
|---|---|
str
|
Rendered PJM script text. |
qcsc_prefect_adapters.fugaku.builder.write_script_file ¶
write_script_file(
*, work_dir: Path, filename: str, text: str
) -> Path
Write a rendered job script into the work directory.
.. note::
This function is expected to be called inside
qcsc_prefect_executor.fugaku.run.run_fugaku_job.
Workflow authors normally do not need to call it directly.
.. note::
The text argument is expected to come from render_script,
which renders the .j2 template specified by _TEMPLATE.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
work_dir
|
Path
|
Base working directory where the script file is created. |
required |
filename
|
str
|
Script file name (for example |
required |
text
|
str
|
Rendered script text. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Absolute path to the created job script file. |
qcsc_prefect_adapters.fugaku.runtime.SubmitResult
dataclass
¶
SubmitResult(job_id: str, raw_output: str)
Submission result returned after PJM accepts a batch script.
Attributes:
| Name | Type | Description |
|---|---|---|
job_id |
str
|
PJM job id parsed from |
raw_output |
str
|
Raw, stripped stdout emitted by |
qcsc_prefect_adapters.fugaku.runtime.FugakuPJMRuntime ¶
Async runtime wrapper for Fugaku PJM scheduler commands.
The runtime maps to the core PJM commands used on Fugaku: pjsub for
submission, pjstat for status polling, and pjdel for cancellation.
Workflow code usually calls
qcsc_prefect_executor.fugaku.run.run_fugaku_job or
qcsc_prefect_executor.from_blocks.run_job_from_blocks instead.
submit
async
¶
submit(
script_path: Path, *, cwd: Path | None = None
) -> SubmitResult
Submit a PJM script with pjsub.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
script_path
|
Path
|
Path to the PJM script file. |
required |
cwd
|
Path | None
|
Optional working directory for |
None
|
Returns:
| Type | Description |
|---|---|
SubmitResult
|
Parsed submission result including job id and raw output. |
Raises:
| Type | Description |
|---|---|
SubmitError
|
If submission fails or job id cannot be parsed. |
wait_final_status
async
¶
wait_final_status(
job_id: str,
*,
watch_poll_interval: float = 10.0,
timeout_seconds: float | None = None,
) -> dict[str, Any]
Poll PJM status until a terminal state is reached.
This method first checks the active job view with pjstat -v and
falls back to the historical view with pjstat -H -v when needed.
The job is considered terminal when PJM reports EXT or CCL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_id
|
str
|
Target PJM job id. |
required |
watch_poll_interval
|
float
|
Poll interval in seconds. |
10.0
|
timeout_seconds
|
float | None
|
Optional timeout for waiting terminal status. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Parsed final |
Raises:
| Type | Description |
|---|---|
WaitTimeout
|
If timeout is exceeded. |
RuntimeError
|
If an underlying |
cancel
async
¶
cancel(job_id: str) -> None
Cancel a PJM job using pjdel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_id
|
str
|
Target PJM job id. |
required |
Raises:
| Type | Description |
|---|---|
CancelError
|
If cancellation fails. |
qcsc_prefect_executor.fugaku.run.FugakuRunResult
dataclass
¶
FugakuRunResult(
job_id: str,
exit_status: int,
state: str,
job_status: dict[str, Any],
)
Normalized result returned by run_fugaku_job.
Attributes:
| Name | Type | Description |
|---|---|---|
job_id |
str
|
PJM job id returned by |
exit_status |
int
|
Integer exit status derived from PJM |
state |
str
|
Final PJM state, such as |
job_status |
dict[str, Any]
|
Parsed final PJM status dictionary from |
qcsc_prefect_executor.fugaku.run.run_fugaku_job
async
¶
run_fugaku_job(
*,
work_dir: Path,
script_filename: str,
exec_profile: ExecutionProfile,
req: FugakuJobRequest,
watch_poll_interval: float = 10.0,
timeout_seconds: float | None = None,
metrics_artifact_key: str = "fugaku-job-metrics",
) -> FugakuRunResult
Execute a Fugaku job end-to-end from runtime models.
.. note:: This function is the high-level executor entrypoint. It internally renders a script, submits it, waits for final status, captures logs, parses stats, and publishes a metrics artifact.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
work_dir
|
Path
|
Working directory where scripts and job outputs are written. |
required |
script_filename
|
str
|
Job script filename to create in |
required |
exec_profile
|
ExecutionProfile
|
Scheduler-independent execution profile. |
required |
req
|
FugakuJobRequest
|
Fugaku-specific scheduler request fields. |
required |
watch_poll_interval
|
float
|
Poll interval in seconds for job status checks. |
10.0
|
timeout_seconds
|
float | None
|
Optional timeout for waiting final status. |
None
|
metrics_artifact_key
|
str
|
Prefect artifact key for job metrics table. |
'fugaku-job-metrics'
|
Returns:
| Type | Description |
|---|---|
FugakuRunResult
|
|
FugakuRunResult
|
final scheduler status payload. |
Slurm API¶
qcsc_prefect_adapters.slurm.builder.SlurmJobRequest
dataclass
¶
SlurmJobRequest(
partition: str,
executable: str,
account: str | None = None,
qpu: str | None = None,
)
Target-specific request fields required to build a Slurm batch job.
Attributes:
| Name | Type | Description |
|---|---|---|
partition |
str
|
Slurm partition name passed to |
executable |
str
|
Absolute or scheduler-visible command path to execute. |
account |
str | None
|
Optional Slurm account passed to |
qpu |
str | None
|
Optional QPU resource selector emitted by the Slurm template. |
qcsc_prefect_adapters.slurm.builder.to_slurm_template_kwargs ¶
to_slurm_template_kwargs(
*, exec_profile: ExecutionProfile, req: SlurmJobRequest
) -> dict
Build template variables for the Slurm job script.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exec_profile
|
ExecutionProfile
|
Scheduler-independent execution profile. |
required |
req
|
SlurmJobRequest
|
Slurm-specific scheduler request fields. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
A dictionary that can be passed to the Slurm Jinja template. |
qcsc_prefect_adapters.slurm.builder.render_script ¶
render_script(
*,
work_dir: Path,
exec_profile: ExecutionProfile,
req: SlurmJobRequest,
) -> str
Render Slurm job script text from the configured Jinja template.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
work_dir
|
Path
|
Working directory injected into the template. |
required |
exec_profile
|
ExecutionProfile
|
Scheduler-independent execution profile. |
required |
req
|
SlurmJobRequest
|
Slurm-specific scheduler request fields. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Rendered Slurm script text. |
qcsc_prefect_adapters.slurm.builder.write_script_file ¶
write_script_file(
*, work_dir: Path, filename: str, text: str
) -> Path
Write a rendered Slurm script into the work directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
work_dir
|
Path
|
Base working directory where the script file is created. |
required |
filename
|
str
|
Script file name, for example |
required |
text
|
str
|
Rendered script text. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Absolute path to the created job script file. |
qcsc_prefect_adapters.slurm.runtime.SubmitResult
dataclass
¶
SubmitResult(job_id: str, raw_output: str)
Submission result returned after a scheduler accepts a batch script.
Attributes:
| Name | Type | Description |
|---|---|---|
job_id |
str
|
Scheduler job id parsed from the submission command output. |
raw_output |
str
|
Raw, stripped stdout emitted by the submission command. |
qcsc_prefect_adapters.slurm.runtime.SlurmRuntime ¶
Async runtime wrapper for Slurm scheduler commands.
This class is the low-level boundary around sbatch, sacct, and
scancel. Workflow code usually calls
qcsc_prefect_executor.slurm.run.run_slurm_job or
qcsc_prefect_executor.from_blocks.run_job_from_blocks instead.
submit
async
¶
submit(
script_path: Path, *, cwd: Path | None = None
) -> SubmitResult
Submit a Slurm batch script with sbatch --parsable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
script_path
|
Path
|
Path to the generated Slurm script. |
required |
cwd
|
Path | None
|
Optional working directory for |
None
|
Returns:
| Type | Description |
|---|---|
SubmitResult
|
Parsed submission payload containing the Slurm job id. |
Raises:
| Type | Description |
|---|---|
SubmitError
|
If |
wait_final_status
async
¶
wait_final_status(
job_id: str,
*,
watch_poll_interval: float = 10.0,
timeout_seconds: float | None = None,
) -> dict[str, Any]
Poll sacct until the job reaches a terminal state.
The returned dictionary is normalized to the fields requested from
sacct: JobID, State, ExitCode, Elapsed,
AllocCPUS, and NodeList.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_id
|
str
|
Slurm job id to watch. |
required |
watch_poll_interval
|
float
|
Seconds to wait between |
10.0
|
timeout_seconds
|
float | None
|
Optional maximum wait time. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Parsed terminal |
Raises:
| Type | Description |
|---|---|
WaitTimeout
|
If |
RuntimeError
|
If an underlying |
cancel
async
¶
cancel(job_id: str) -> None
Cancel a Slurm job using scancel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_id
|
str
|
Target Slurm job id. |
required |
Raises:
| Type | Description |
|---|---|
CancelError
|
If |
qcsc_prefect_executor.slurm.run.SlurmRunResult
dataclass
¶
SlurmRunResult(
job_id: str,
exit_status: int,
state: str,
job_status: dict[str, Any],
)
Normalized result returned by run_slurm_job.
Attributes:
| Name | Type | Description |
|---|---|---|
job_id |
str
|
Slurm job id returned by |
exit_status |
int
|
Integer process exit code parsed from Slurm |
state |
str
|
Final Slurm job state. |
job_status |
dict[str, Any]
|
Parsed terminal |
qcsc_prefect_executor.slurm.run.run_slurm_job
async
¶
run_slurm_job(
*,
work_dir: Path,
script_filename: str,
exec_profile: ExecutionProfile,
req: SlurmJobRequest,
watch_poll_interval: float = 10.0,
timeout_seconds: float | None = None,
metrics_artifact_key: str = "slurm-job-metrics",
) -> SlurmRunResult
Execute a Slurm job end-to-end from runtime models.
This high-level executor renders the Slurm script, submits it with
sbatch, waits for terminal sacct status, captures stdout/stderr
files, and publishes a Prefect table artifact with scheduler metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
work_dir
|
Path
|
Working directory where scripts and job outputs are written. |
required |
script_filename
|
str
|
Job script filename to create in |
required |
exec_profile
|
ExecutionProfile
|
Scheduler-independent execution profile. |
required |
req
|
SlurmJobRequest
|
Slurm-specific scheduler request fields. |
required |
watch_poll_interval
|
float
|
Poll interval in seconds for job status checks. |
10.0
|
timeout_seconds
|
float | None
|
Optional timeout for waiting final status. |
None
|
metrics_artifact_key
|
str
|
Prefect artifact key for job metrics table. |
'slurm-job-metrics'
|
Returns:
| Type | Description |
|---|---|
SlurmRunResult
|
|
SlurmRunResult
|
final scheduler status payload. |
qcsc_prefect_executor.slurm.from_blocks.run_slurm_job_from_blocks
async
¶
run_slurm_job_from_blocks(
*,
command_block_name: str,
execution_profile_block_name: str,
hpc_profile_block_name: str,
work_dir: Path,
script_filename: str,
user_args: list[str] | None = None,
watch_poll_interval: float = 10.0,
timeout_seconds: float | None = None,
metrics_artifact_key: str = "slurm-job-metrics",
) -> SlurmRunResult
Backward-compatible wrapper around run_job_from_blocks for Slurm.
DICE API¶
qcsc_prefect_dice.solver_job.DiceSHCISolverJob ¶
Bases: Block
Prefect block facade for DICE execution through qcsc-prefect blocks.
run
async
¶
run(
ci_strings: tuple[ndarray, ndarray],
one_body_tensor: ndarray,
two_body_tensor: ndarray,
norb: int,
nelec: tuple[int, int],
spin_sq: float | None = None,
) -> SCIResult
Run DICE and return parsed SHCI outputs.
qcsc_prefect_dice.block_utils.register_dice_block_types ¶
register_dice_block_types() -> None
Register common block schemas used by DICE integrations.
qcsc_prefect_dice.block_utils.create_dice_blocks ¶
create_dice_blocks(
*,
hpc_target: Literal["miyabi", "fugaku"],
project: str,
queue: str,
root_dir: str,
dice_executable: str,
command_block_name: str = "cmd-dice-solver",
execution_profile_block_name: str | None = None,
hpc_profile_block_name: str | None = None,
solver_block_name: str = "dice-solver",
command_name: str = "dice",
executable_key: str = "dice_solver",
profile_name: str = "dice-mpi",
launcher: Literal[
"single", "mpirun", "mpiexec", "mpiexec.hydra"
]
| None = None,
num_nodes: int = 1,
mpiprocs: int = 4,
ompthreads: int | None = None,
walltime: str = "01:00:00",
resource_class: Literal["cpu", "gpu"] = "cpu",
modules: list[str] | None = None,
mpi_options: list[str] | None = None,
pre_commands: list[str] | None = None,
environments: dict[str, str] | None = None,
script_filename: str | None = None,
metrics_artifact_key: str | None = None,
select_cutoff: float = 0.0005,
davidson_tol: float = 1e-05,
energy_tol: float = 1e-10,
max_iter: int = 10,
return_sci_state: bool = True,
gfscache: str | None = None,
spack_modules: list[str] | None = None,
mpi_options_for_pjm: list[str] | None = None,
pjm_resources: list[str] | None = None,
) -> dict[str, str]
Create the standard block set required to run DICE on qcsc-prefect.
This helper keeps a typed, explicit API on purpose. Algorithm-specific wrappers can translate TOML or CLI config dictionaries into these arguments without leaking config-shape coupling into the shared package.
qcsc_prefect_dice.io_utils.make_job_work_dir ¶
make_job_work_dir(base_work_dir: Path) -> Path
Create a unique work directory for one DICE execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_work_dir
|
Path
|
Parent directory under which per-job directories are created. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Newly created job directory named with a UTC timestamp and short random |
Path
|
suffix. |
Raises:
| Type | Description |
|---|---|
FileExistsError
|
If the generated unique directory already exists. |
OSError
|
If the directory cannot be created. |
qcsc_prefect_dice.io_utils.prep_dice_input_files ¶
prep_dice_input_files(
*,
work_dir: Path,
ci_strings: tuple[ndarray, ndarray],
one_body_tensor: ndarray,
two_body_tensor: ndarray,
norb: int,
nelec: tuple[int, int],
spin_sq: float | None,
select_cutoff: float,
davidson_tol: float,
energy_tol: float,
max_iter: int,
) -> None
Prepare all input files required by the DICE SHCI executable.
The helper writes fcidump.txt from molecular integrals, renders
input.dat from solver controls, and serializes alpha/beta determinant
seeds into AlphaDets.bin and BetaDets.bin using the DICE binary
format expected by the bundled template.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
work_dir
|
Path
|
Directory where DICE input files are written. |
required |
ci_strings
|
tuple[ndarray, ndarray]
|
Alpha and beta determinant bitstrings used as the initial CI space. |
required |
one_body_tensor
|
ndarray
|
One-electron integral tensor passed to PySCF's FCIDUMP writer. |
required |
two_body_tensor
|
ndarray
|
Two-electron integral tensor passed to PySCF's FCIDUMP writer. |
required |
norb
|
int
|
Number of spatial orbitals. |
required |
nelec
|
tuple[int, int]
|
Number of alpha and beta electrons. |
required |
spin_sq
|
float | None
|
Optional target spin-squared value for |
required |
select_cutoff
|
float
|
DICE selection cutoff. |
required |
davidson_tol
|
float
|
Davidson solver convergence tolerance. |
required |
energy_tol
|
float
|
SCI energy convergence tolerance. |
required |
max_iter
|
int
|
Maximum number of HCI iterations. |
required |
Raises:
| Type | Description |
|---|---|
OSError
|
If any input file cannot be written. |
OverflowError
|
If a determinant bitstring cannot be encoded into the fixed-width DICE determinant representation. |
qcsc_prefect_dice.io_utils.read_dice_output_files ¶
read_dice_output_files(
*,
work_dir: Path,
norb: int,
nelec: tuple[int, int],
return_sci_state: bool,
) -> SCIResult
Read DICE output files and reconstruct an SCIResult.
The helper reads orbital occupancies from spin1RDM.0.0.txt and the
variational energy from shci.e. When return_sci_state is true, it
also parses dets.bin and reconstructs a
qiskit_addon_sqd.fermion.SCIState compatible with the SQD addon.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
work_dir
|
Path
|
Directory containing DICE output files. |
required |
norb
|
int
|
Number of spatial orbitals. |
required |
nelec
|
tuple[int, int]
|
Number of alpha and beta electrons. |
required |
return_sci_state
|
bool
|
Whether to parse |
required |
Returns:
| Type | Description |
|---|---|
SCIResult
|
Parsed SCI result containing energy, optional SCI state, and alpha/beta |
SCIResult
|
orbital occupancies. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If a required DICE output file is missing. |
ValueError
|
If text output cannot be parsed into numeric arrays. |
error
|
If binary output is truncated or malformed. |