Options
The SDK lets you pass advanced options to the state preparation algorithm, so you can choose the method, the output format, and method-specific tuning parameters.
Arguments
Section titled “Arguments”state,state_vectororparams: the input state vector. It can be a list, a numpyndarray, a scipy sparsesparray, or (for Qiskit) aStatevector.opt_params: every other setting, as anOptParamsobject or a plain dict with the same keys.q_alchemy_as_qasmalso accepts them as keyword arguments.
Options
Section titled “Options”The OptParams object (from q_alchemy.initialize, also re-exported by the Qiskit and PennyLane integrations) supports these fields:
max_fidelity_loss: how much fidelity you are willing to give up for a shallower circuit. Defaults to0.0, an exact preparation. The SDK sends this to the service asmin_fidelity = 1 - max_fidelity_loss.basis_gates: the gate set the returned circuit is transpiled to. Defaults to["u", "cx"].api_key: your Q-Alchemy API key. Defaults to theQ_ALCHEMY_API_KEYenvironment variable. Keep it safe!initialization_method: the algorithm to use, fromInitializationMethods. Defaults toInitializationMethods.AUTO. The available values are:InitializationMethods.AUTO: runs several Tucker candidates (iterative and hierarchical, as resources allow) at your fidelity budget and keeps the cheapest realized circuit. Trivial inputs such as single-qubit and single-basis states take an exact fast path.InitializationMethods.ITERATIVE_TUCKER: the iterative Tucker initializer.InitializationMethods.HIERARCHICAL_TUCKER: the hierarchical Tucker initializer.InitializationMethods.SWAP_PIVOT: the swap-pivot initializer, suited to very sparse states.InitializationMethods.BAA_LOW_RANK: the BAA low-rank initializer. It is limited to 12 qubits.
use_qasm3: experimental. IfTrue, the circuit is returned as OpenQASM 3 instead of OpenQASM 2. Defaults toFalse.extra_kwargs: method-specific options, as a dict. Defaults to{}.remove_data: delete the job and its uploaded data once the result has been fetched. Defaults toTrue.job_completion_timeout_sec: how long to wait for the job before giving up. Defaults to300.
Method-specific options
Section titled “Method-specific options”Method-specific options go in extra_kwargs as a plain dict. The SDK serializes it for you:
from q_alchemy.initialize import OptParams, InitializationMethods
opt_params = OptParams( max_fidelity_loss=0.05, initialization_method=InitializationMethods.ITERATIVE_TUCKER, extra_kwargs={"max_iterations": 10, "factors_size": 4},)AUTO options
Section titled “AUTO options”cost_function: how the candidates are ranked. Defaults to"cx_then_depth". The other values are"depth_then_cx","two_qubit_then_depth","cx+depth","cx"and"depth".basis_gates: the gate set used to compare candidates. Defaults to["u", "cx"]. This is separate from the top-levelbasis_gates(see below).transpile_optimization_level: the Qiskit optimization level used when comparing candidates. Defaults to1.seed_transpiler: the transpiler seed, for reproducible comparisons. Defaults to0.dominant_basis_fast_path: a zero-CNOT shortcut for states dominated by a single basis state. Defaults toTrue.fidelity_tolerance: the numerical slack allowed on the fidelity budget.geometric_entanglement: an optional geometric-entanglement hint in[0, 1].check_normalization: whether to check that the input state is normalized. Defaults toTrue.
Iterative Tucker options
Section titled “Iterative Tucker options”These apply only with initialization_method=InitializationMethods.ITERATIVE_TUCKER:
max_iterations: the maximum number of iterations. If omitted or not positive, a value is chosen from the number of qubits.factors_size: the initial Tucker factor size. If omitted,0, or outside the valid range, it is sized automatically.max_stepup: the maximum allowed increase in factor size when the search stalls. Defaults to0.fallback: allow fallback behavior when the iterative search does not find an acceptable solution. Defaults toTrue.perturbation: what to do when the partition search stagnates. Defaults toNone, meaning no perturbation.geometric_entanglement: an optional geometric-entanglement hint used by some fallback paths. If omitted or outside[0, 1], it defaults to0.0.check_normalization: whether to check that the input state is normalized. Defaults toTrue.barriers: insert barriers between iterative layers, for debugging or benchmarking. They hurt transpilation, so leave this off in production. Defaults toFalse.
Other methods
Section titled “Other methods”HIERARCHICAL_TUCKER:geometric_entanglementandcheck_normalization.SWAP_PIVOT:aux.BAA_LOW_RANK:strategy(defaults to"greedy"),use_low_rank(defaults toTrue),max_combination_size,iso_schemeandunitary_scheme.
Things to know
Section titled “Things to know”- Set the fidelity with
max_fidelity_lossonOptParams, not inextra_kwargs. Every method also acceptsmax_fidelity_lossinsideextra_kwargs, but if you put it there it silently overrides the top-level value. - Under
AUTO, the top-levelbasis_gatesonly affects the final transpilation. Candidates are compared onu/cxcost unless you also passextra_kwargs={"basis_gates": [...]}. AUTOis a portfolio, not a fixed fallback chain. The candidates it tries depend on the qubit count and sparsity of your state, so the method reported in the result summary can differ between inputs.