Skip to content

VQEStabilityDiagnosticResult

from cascaqit import VQEStabilityDiagnosticResult

VQEStabilityDiagnosticResult

VQEStabilityDiagnosticResult(
    diagnostic_id: str,
    source_result_hash: str,
    source_result: VariationalResult[Any],
    config: VQEStabilityConfig,
    starts: tuple[VQEStartStabilityDiagnosticIR, ...],
    selected_start_index: int,
    status: VQEStabilityStatus,
    optimality_claim: Literal[
        "not_claimed"
    ] = "not_claimed",
    convergence_claim: Literal[
        "not_claimed"
    ] = "not_claimed",
    schema_version: str = VQE_STABILITY_SCHEMA_VERSION,
)

Retain a read-only stability diagnosis with its complete source result. Only native-SPSA VQE records are accepted. Prefer result.diagnose_stability() or create() to manually assembling starts and status.

source_result/hash binds the original result, config stores thresholds, and starts retains each initial point’s terminal window, individual checks, costs and termination. selected_start_index follows the source result. Overall status reflects that selected start only, not stability of every start. Status is stable, unstable or insufficient_evidence.

Construction and restoration rederive start diagnostics and verify the source digest, diagnostic ID and overall status. Both optimality_claim and convergence_claim must remain not_claimed. To change thresholds, call create() again rather than editing a saved status.

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, VQEStabilityDiagnosticResult

diagnostic = VQEStabilityDiagnosticResult.create(result, VQEStabilityConfig())
assert diagnostic.status == "insufficient_evidence"
assert diagnostic.convergence_claim == "not_claimed"
restored = VQEStabilityDiagnosticResult.from_json(diagnostic.to_json())
assert restored.stable_hash() == diagnostic.stable_hash()
assert diagnostic.report().profile == "algorithm"

create

create(
    source_result: VariationalResult[Any],
    config: VQEStabilityConfig,
) -> VQEStabilityDiagnosticResult

Derive diagnostics, ID and source digest from a complete result and VQEStabilityConfig, returning VQEStabilityDiagnosticResult without calling a simulator. Invalid types, non-SPSA VQE and missing start records raise.

report

report(
    output: str | PathLike[str] | None = None,
    *,
    language: Literal["en", "zh"] = "en",
    title: str | None = None,
) -> ExperimentReport

Return an algorithm-profile ExperimentReport. A nonempty output immediately saves HTML, with language selecting that save’s language and title optionally overriding the title. With output=None, only return the report; later to_html()/save() calls still need an explicit language, as this argument is not retained.

from_dict

from_dict(
    data: Mapping[str, Any],
) -> VQEStabilityDiagnosticResult

Restore VQEStabilityDiagnosticResult from a dictionary. Restore the complete source result and configuration, then recompute and check diagnostics. Inconsistent source data, digests or status are rejected. Missing required fields or invalid values can raise KeyError, TypeError or ValueError.

from_json

from_json(text: str) -> VQEStabilityDiagnosticResult

Parse a JSON object and call from_dict(), returning VQEStabilityDiagnosticResult. Invalid JSON raises a parsing error; a non-object root raises TypeError.

to_dict

to_dict() -> dict[str, Any]

Return a JSON-compatible dictionary of the complete record, including nested objects. This saves existing data without rerunning the experiment.

to_json

to_json(*, indent: int | None = None) -> str

Return the complete record as a JSON string. indent controls formatting; no file is written.

stable_hash

stable_hash() -> str

Return the SHA-256 digest of the complete canonical JSON record for content comparison and provenance. It neither proves the experiment’s conclusion nor establishes physical equivalence.