Cloud API¶
run_simulation
¶
run_simulation(
config_dir: str | Path,
job_type: Literal["palace", "meep"] = "palace",
verbose: bool = True,
on_started: Callable | None = None,
parent_dir: str | Path | None = None,
) -> RunResult
Run a simulation on GDSFactory+ cloud (blocking).
This function handles the complete workflow:
1. Uploads simulation files from config_dir
2. Starts the simulation job
3. Creates a structured directory sim-data-{job_name}/
with input/ (config files) and output/ (results) sub-dirs
4. Waits for completion
5. Downloads results into output/
Parameters:
-
config_dir(str | Path) –Directory containing the simulation config files.
-
job_type(Literal['palace', 'meep'], default:'palace') –Type of simulation (default: "palace").
-
verbose(bool, default:True) –Print progress messages (default True).
-
on_started(Callable | None, default:None) –Optional callback called with job object when simulation starts.
-
parent_dir(str | Path | None, default:None) –Where to create the sim directory. Defaults to the current working directory.
Returns:
-
RunResult–RunResult with sim_dir, files dict, and job_name.
Raises:
-
RuntimeError–If simulation fails
Example
result = gcloud.run_simulation("./sim", job_type="palace") Uploading simulation... done Job started: palace-abc123 Waiting for completion... done (2m 34s) Downloading results... done print(result.sim_dir) sim-data-palace-abc123/
get_status
¶
wait_for_results
¶
wait_for_results(
*job_ids: str,
verbose: Literal["quiet", "status", "full"] = "status",
parent_dir: str | Path | None = None,
poll_interval: float = 5.0,
) -> Any
Wait for one or more jobs to finish, then download and parse results.
Accepts job IDs as positional args or a single list/tuple::
wait_for_results(id1, id2)
wait_for_results([id1, id2])
For a single job, returns the parsed result directly. For multiple jobs, returns a list of results (same order as input).
Parameters:
-
*job_ids(str, default:()) –One or more job ID strings, or a single list/tuple of IDs.
-
verbose(Literal['quiet', 'status', 'full'], default:'status') –Output mode:
"quiet"— no output."status"— status line only (default)."full"— stream solver logs live (timestamps stripped). -
parent_dir(str | Path | None, default:None) –Where to create sim-data directories (default: cwd).
-
poll_interval(float, default:5.0) –Seconds between status polls (default 5.0).
Returns:
-
Any–Parsed result (single job) or list of parsed results (multiple jobs).
RunResult
dataclass
¶
Result caching¶
Passing check_cache=True to sim.run() looks for a completed cloud job with
byte-identical inputs and reuses its results instead of submitting a new job:
The cache key is derived from the files written by write_config() — the same
bytes the solver consumes — rather than from the simulation object, so it also
covers changes to the generated solver script. A lookup failure is never fatal:
it degrades to a normal submit.
check_cache
¶
Look up a previously completed job with identical inputs.
Never raises: a cache lookup is an optimization, so an unsupported SDK,
a transient network error, or a server error all degrade to a miss and
the caller submits the job normally. Those degraded paths are logged at
WARNING — silently returning a miss makes a permanently broken
lookup indistinguishable from a cold cache.
Parameters:
-
job_type(str) –Solver name, e.g.
"meep"or"palace". -
input_hash(str) –Value from :func:
gsim.hashing.compute_input_hash.
Returns:
-
str | None–job_idof the cached job, orNoneon a miss.
check_cache_for_dir
¶
compute_input_hash
¶
Compute the cloud cache key for a prepared simulation input directory.
Folds the solver name and the gsim version into the directory digest. Including the gsim version is deliberately conservative: gsim generates the solver driver script, so an upgrade may change results even when the written inputs are byte-identical. It can be dropped once the server-side key includes the solver image version.
Parameters:
-
input_dir(str | Path) –Directory holding the files that will be uploaded.
-
job_type(str) –Solver name, e.g.
"meep"or"palace".
Returns:
-
str–"sha256:<hex>"— the value to pass asinput_hash.
Raises:
-
FileNotFoundError–If input_dir does not exist.
-
ValueError–If input_dir contains no files.
Example
compute_input_hash("./sim", "meep") # doctest: +SKIP 'sha256:6a1f...'