Skip to content

VQESamplingBenchmarkConfig

from cascaqit import VQESamplingBenchmarkConfig

VQESamplingBenchmarkConfig

VQESamplingBenchmarkConfig(
    repeats: int,
    objective_evaluation_budget: int,
    optimizer: OptimizerConfig,
    measurement: PauliMeasurementConfig,
    sampled_selection: SampledSelectionConfig,
    fixed_objective_repeats: int = 2,
    adaptive_objective_repeats: int = 2,
    adaptive_max_objective_repeats: int = 4,
    adaptive_standard_error_target: float = 0.05,
    final_shots: int = 1024,
    confidence_level: float = 0.95,
    root_seed: int = 0,
    schema_version: str = VQE_SAMPLING_BENCHMARK_SCHEMA_VERSION,
)

Configure a paired comparison of four VQE objective strategies: exact, sampled_single, sampled_fixed and sampled_adaptive. Execution begins only when passed to VQE.benchmark_sampling(). All strategies in a repeat share a derived seed and initial parameters. repeats must be at least 2, with all four strategies run each time.

optimizer must use SPSA, starts=1, initialization="random" and seed=None, with no max_evaluations or max_backend_executions. The benchmark supplies seeds and budgets. Base SPSA must use one fixed objective repeat. The positive objective_evaluation_budget must be at least 4 * max(fixed_objective_repeats, adaptive_objective_repeats). More directions, calibration or stopping requirements can need larger budgets, checked at execution.

measurement sets grouped measurement and shots for sampled strategies; sampled_selection configures independent confirmation. fixed_objective_repeats and adaptive_objective_repeats must be at least 2; adaptive_max_objective_repeats must exceed its initial count and adaptive_standard_error_target must be positive. final_shots is a positive integer, confidence_level lies in (0,1), and root_seed is nonnegative.

A common objective-evaluation ceiling does not mean identical backend calls or total shots. Confirmation, final sampling and independent exact diagnostics are counted separately. Selected sampled points receive additional exact evaluation. The “exact reference” is the same repeat’s exact-objective optimization result, not a known ground state. This entry point currently has no noise/options arguments.

from cascaqit import HamiltonianTerm, OptimizerConfig, PauliHamiltonian, PauliZ, VQE

vqe = VQE(PauliHamiltonian("z", (HamiltonianTerm("z", 1.0, PauliZ("q0")),),
                           logical_order=("q0",)))
from cascaqit import PauliMeasurementConfig, SampledSelectionConfig, VQESamplingBenchmarkConfig

config = VQESamplingBenchmarkConfig(
    repeats=2, objective_evaluation_budget=8,
    optimizer=OptimizerConfig(method="SPSA", max_iterations=1),
    measurement=PauliMeasurementConfig(shots_per_group=16),
    sampled_selection=SampledSelectionConfig(candidate_count=2, repeats_per_candidate=2),
    final_shots=8, root_seed=7,
)
assert config.optimizer.seed is None
assert config.objective_evaluation_budget == 8
assert VQESamplingBenchmarkConfig.from_json(config.to_json()) == config

from_dict

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

Restore VQESamplingBenchmarkConfig from a dictionary. repeats, objective_evaluation_budget and all three nested configurations are required. Strategy and budget constraints are rechecked on restoration. Missing required fields or invalid values can raise KeyError, TypeError or ValueError.

from_json

from_json(text: str) -> VQESamplingBenchmarkConfig

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

to_dict

to_dict() -> dict[str, Any]

Return a JSON-compatible dictionary, serializing nested objects and converting tuples to arrays. This stores the declaration, not an execution result.

to_json

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

Return a JSON string without writing a file. indent=None uses compact formatting; supply an indentation width for readable output.

stable_hash

stable_hash() -> str

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.