Overview
Calculations are run by calling the qccompute.compute() function with the relevant arguments and keywords like this:
from qcdata import Structure, ProgramInput
from qccompute import compute
# Create the Structure
structure = Structure(
symbols=["O", "H", "H"],
geometry=[ # type: ignore
[0.0, 0.0, 0.0],
[0.52421003, 1.68733646, 0.48074633],
[1.14668581, -0.45032174, -1.35474466],
],
)
# Define the program input
prog_input = ProgramInput(
program="terachem",
structure=structure,
calctype="energy",
model={"method": "wb97xd3", "basis": "def2-svp"},
keywords={"purify": "no", "restricted": False},
)
# Run the calculation; will return a ProgramOutput or raise an exception
result = compute(prog_input, collect_files=True)
The compute function resolves a codec and executes its native invocation. It also accepts an explicit local codec=. The available arguments are:
qccompute.main.compute(input_data: InputType | Sequence[InputType], *, codec: qccodec.Codec | None = None, environment: Mapping[str, str] | None = None, scratch_dir: StrOrPath | None = None, rm_scratch_dir: bool = True, collect_logs: bool = True, collect_files: bool = False, collect_wfn: bool = False, update_func: Callable[..., None] | None = None, update_interval: float | None = None, print_logs: bool = False, raise_exc: bool = True, propagate_wfn: bool = False, options: Mapping[str, Any] | None = None, timeout: float | None = None, executables: Mapping[str, str] | None = None, max_workers: int | None = None) -> ProgramOutput[InputType, Data] | list[ProgramOutput[InputType, Data]]
¶
Compute one input, or a list of inputs in parallel, with a local runner.
A single input returns a single ProgramOutput. A list (or tuple) returns a
list of outputs in input order; its inputs may be for different programs, and
every other argument applies to each of them. Calculations that run as programs
(ORCA, xtb, Psi4, ...) run side by side in threads. Calculations that run in
Python (geomeTRIC, tblite) take over a process's output streams while they run,
so two or more of them run side by side in worker processes, which start with the
numerical libraries' thread counts set to their share. All of them draw on the
max_workers budget. Inputs a codec can evaluate together (machine-learned
potentials sharing a model) run in batches in this process, one call per batch
of up to codec.max_batch; execution.extras records batch_size and
batch_index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_data |
InputType | Sequence[InputType]
|
A qcdata input object, such as ProgramInput or FileInput, or a list of them. |
required |
codec |
Codec | None
|
The |
None
|
environment |
Mapping[str, str] | None
|
Process environment overrides mapping strings to strings. Applied after the inherited environment and codec defaults. Subprocess overrides affect only the child. Python calls temporarily change the current process's environment, working directory, and output streams; use separate processes for parallel Python calculations. Environment settings must be applied before the relevant native library initializes. |
None
|
scratch_dir |
StrOrPath | None
|
The calculation directory, not its parent; not accepted with a list of inputs. If None, create a directory in the system's temporary directory. Each concurrent call needs its own directory. This directory, including any existing contents, is deleted when rm_scratch_dir is True. |
None
|
rm_scratch_dir |
bool
|
Delete the calculation directory after execution, decoding, and file collection finish, including on failure. |
True
|
collect_logs |
bool
|
Retain merged stdout/stderr in ProgramOutput.logs. Available logs are always retained for failed calculations. |
True
|
collect_files |
bool
|
Collect files from the calculation directory, excluding files supplied in input_data.files. FileInput always collects these files. Decoders can access generated files regardless of this setting. |
False
|
collect_wfn |
bool
|
Collect wavefunction files identified by the codec. Not every codec supports this. Ignored when collect_files is True, which retains all generated files including wavefunction files. |
False
|
update_func |
Callable[..., None] | None
|
Callback accepting (all_logs, new_logs), both strings. Subprocess updates arrive during execution; Python output is delivered after invocation. No callback is made for empty output. For a list of inputs it receives (index, all_logs, new_logs), where index is the input's position, and is called from the threads running the calculations, so it must be thread-safe. |
None
|
update_interval |
float | None
|
Minimum seconds between subprocess log updates; defaults to 0.5. Updates are line-based, and final output is delivered without waiting for this interval. Has no effect on Python calls. |
None
|
print_logs |
bool
|
Print merged stdout/stderr using the update callback. Ignored
when update_func is supplied. Python logs print after invocation. For a
list, each line is prefixed with its input's index, e.g. |
False
|
raise_exc |
bool
|
Raise a qccompute exception on calculation failure, with the
completed ProgramOutput attached as .prog_output. If False, return
the failed output instead. Partial results and diagnostics are retained
when available. For a list, every calculation runs first; then
|
True
|
propagate_wfn |
bool
|
For integrations that request child calculations, such as geometry optimization, use the child codec's restart support to prepare each input from the previous result. Requires a child-calculation integration and support for collecting and restarting from wavefunctions. |
False
|
options |
Mapping[str, Any] | None
|
Program-specific decode options passed to the codec, such as
|
None
|
timeout |
float | None
|
Seconds each external program may run before it and the processes
it started are killed, raising |
None
|
executables |
Mapping[str, str] | None
|
Executables to run, keyed by program name, such as
|
None
|
max_workers |
int | None
|
For a list of inputs, the CPU threads program calculations may
use at once. Defaults to the number of CPU cores this process may use.
Each calculation counts the threads its codec declares (ORCA |
None
|
Returns:
| Type | Description |
|---|---|
ProgramOutput[InputType, Data] | list[ProgramOutput[InputType, Data]]
|
A ProgramOutput containing scientific results, execution metadata, and the |
ProgramOutput[InputType, Data] | list[ProgramOutput[InputType, Data]]
|
requested logs and files, or a list of them in input order for a list of |
ProgramOutput[InputType, Data] | list[ProgramOutput[InputType, Data]]
|
inputs. Failed calculations may contain partial results. |
Raises:
| Type | Description |
|---|---|
CodecNotFoundError
|
No codec is available for the requested program. |
InputError
|
Inputs or compute options are unsupported or invalid. |
ProgramNotFoundError
|
The executable cannot be found, or a codec explicitly reports an unavailable dependency. |
ProgramTimeoutError
|
A program exceeded |
ExternalProgramError
|
Execution, decoding, artifact collection, or cleanup fails. Unexpected codec exceptions also use this category. |
ComputeErrors
|
For a list of inputs, some calculations failed. |
Calculation exceptions are raised only when raise_exc is True.
Source code in src/qccompute/main.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | |
Examples for each program¶
Complete, runnable scripts for every program and calculation type, with every common option shown and the program's quirks explained, are on the qccodec program pages. The examples here cover qccompute itself: running a program from your own input files and defining a codec for a program qccodec doesn't support.