VQEStabilityConfig¶
from cascaqit import VQEStabilityConfig
VQEStabilityConfig ¶
VQEStabilityConfig(
window_size: int = 3,
min_iterations: int = 3,
objective_range_tolerance: float = 0.001,
update_norm_tolerance: float = 0.001,
gradient_norm_tolerance: float = 0.01,
sampled_standard_error_tolerance: float = 0.05,
schema_version: str = VQE_STABILITY_SCHEMA_VERSION,
)
Configure post-run stability diagnosis for native-SPSA VQE through VariationalResult.diagnose_stability(). It reads saved records without changing online stopping rules or adding samples. Use SPSAStoppingConfig for online stopping.
window_size and min_iterations must be positive integers, with min_iterations >= window_size. Unlike online stopping, this configuration permits window_size=1. All tolerances must be finite and positive.
| Tolerance | Check |
|---|---|
| objective_range_tolerance | Range of the latest window_size plus/minus midpoint proxies and the final center estimate: window_size+1 values |
| update_norm_tolerance | Maximum actual update norm in the terminal window |
| gradient_norm_tolerance | Maximum estimated gradient norm in the terminal window |
| sampled_standard_error_tolerance | Maximum pooled standard error of plus/minus and final estimates for sampled objectives; omitted for exact objectives |
Too few iterations or missing uncertainty gives insufficient_evidence. Complete evidence with a failed check gives unstable; passing every check gives stable. stable describes this window under these thresholds without claiming convergence or optimality.
from cascaqit import HamiltonianTerm, OptimizerConfig, PauliHamiltonian, PauliZ, VQE
vqe = VQE(PauliHamiltonian("z", (HamiltonianTerm("z", 1.0, PauliZ("q0")),),
logical_order=("q0",)))
result = vqe.run(optimizer=OptimizerConfig(method="SPSA", max_iterations=2, seed=7),
initial_parameters=(0.4, 0.2), final_shots=16)
from cascaqit import VQEStabilityConfig
config = VQEStabilityConfig(window_size=3, min_iterations=3)
diagnostic = result.diagnose_stability(config)
assert diagnostic.status == "insufficient_evidence"
assert diagnostic.source_result_hash == result.stable_hash()
assert VQEStabilityConfig.from_json(config.to_json()) == config
Restore VQEStabilityConfig from a dictionary. Omitted fields use defaults; window size, minimum iterations and positive tolerances are rechecked. Missing required fields or invalid values can raise KeyError, TypeError or ValueError.
Parse a JSON object and call from_dict(), returning VQEStabilityConfig. Invalid JSON raises a parsing error; a non-object root raises TypeError.
Return a JSON-compatible dictionary, serializing nested objects and converting tuples to arrays. This stores the declaration, not an execution result.
Return a JSON string without writing a file. indent=None uses compact formatting; supply an indentation width for readable output.
Return the SHA-256 hex digest of canonical JSON. Fields, identifiers and metadata can affect it. Use it to compare saved content, not to decide physical equivalence.