A variational quantum algorithm evaluates a circuit at many parameter values. When the structure and hardware target remain suitable, compiling the parameterized circuit once allows placement and routing to be reused. Compiling after binding may expose additional simplifications at particular angles. The decision depends on the work the experiment will repeat.
Compile the parameterized circuit
The Qiskit plugin provides a pass manager for the 4colors Quantum Compiler. The following excerpts use the helpers and ansatz from the associated example repository. Configure the client as described in the developer documentation.
from qiskit_ibm_runtime.fake_provider import FakeFez
from fourcolors.quantum import compiler
from qaoakit import apikit as ak # shared/qaoakit in the examples repository
pm = compiler.generate_pass_manager(FakeFez(), target=ak.device_target(), time_budget_s=30, seed=1,
approximation_mode="exact")
out = pm.run(ansatz) # a Qiskit circuit that still has your Parameters
res = pm.property_set["fourcolors_result"] # job, billed seconds, verification label The compilation budget determines how much search time is available for the circuit. Keep the target, approximation mode and parameter mapping with the returned implementation.
Bind using the correct parameter identities
params = list(ansatz.parameters) # the objects you compiled with
for values in steps: # one float per parameter
assert len(values) == len(params)
bound = out.assign_parameters(dict(zip(params, values)))
# Confirm parameter order before using a positional binding. When binding by position, confirm the order of the returned circuit's parameters. A name such as t10 can precede t2 in lexicographic order. Parameter objects created independently may also have different identities despite identical names.
A text round trip can create new parameter objects. Bind by name when the names are unique and their mapping to the original variables has been confirmed.
out = compiler.compile(qasm3_text, target=ak.device_target(), time_budget_s=30, seed=1,
approximation_mode="exact").to_qiskit()
bound = out.assign_parameters({p: values_by_name[p.name] for p in out.parameters}) For a Qiskit input, the compiled circuit carries the input's own Parameter objects, so binding by object or by position works as on the input. For a text input, res.parameters lists the names to bind.
Verify the intended scope
For selected bindings, compare the prepared states of the original and compiled circuits with the physical qubits mapped back to the logical order. Include any input placement and required ancillary state. A statevector comparison within a numerical tolerance establishes agreement for the selected prepared inputs. A proof of equivalence across the parameter domain requires an appropriate symbolic or structural argument. Inspect the actual verification status of each compilation rather than inferring it from the approximation mode.
Decide when to compile again
If a reusable compilation costs C₀ and separate compilations cost Cᵢ at each evaluation, the additional classical cost is ΣCᵢ−C₀. Use common units, such as money, or a deadline when comparing that with savings in execution. For an illustration, a rotation Rz(θ) is an identity at θ=0; a compiler with the actual angle can remove it, while a general parameterized circuit must retain its effect for other angles.
A useful comparison uses the same parameter points and completed evaluation counts for both policies. Record the observable estimates, compiled operations and costs, and compare the resulting computation under the same experimental conditions.
The example repository includes the parameter-binding checks and variational-loop scripts. Use the measured cost of the complete experiment to decide whether recompiling at selected points is worthwhile.