cirq.two_qubit_gate_numerical_compilation

Compile a two-qubit unitary onto hardware base gate(s) via numerical optimization.

Implements the NuOp compilation technique of arXiv:2106.15490. The target unitary is decomposed into i layers of a base two-qubit gate sandwiched between parameterized single-qubit gates,

\(k_i \cdot G \cdot k_{i-1} \cdot \ldots \cdot G \cdot k_0 \approx U_t\),

where the angles of the 1-local unitaries \(k_j\) are found by a BFGS numerical optimizer maximizing the decomposition fidelity \(F_d = |\mathrm{Tr}(U_d^\dagger U_t)| / 4\).

The number of layers is grown from 1 upward, optimizing each template in turn, and the first decomposition whose fidelity meets target_fidelity is returned. With several base gates, all of them are tried at each layer count, so the returned decomposition is the one with the fewest layers across all gate types. If no template with at most max_layers layers meets target_fidelity, the highest-fidelity decomposition found is returned with success set to False.

If error rates are given (base_gate_error_rates and/or single_qubit_error_rates), the compiler additionally accounts for hardware noise: instead of stopping at the first decomposition meeting target_fidelity, all (base gate, layer count) combinations up to max_layers are optimized, and the decomposition maximizing the overall fidelity \(F_u = F_d \cdot F_h\) is returned, where the hardware fidelity \(F_h\) is the product of (1 - error_rate) over all gates in the decomposition. This can deliberately select an approximate decomposition with fewer base gates when hardware noise dominates the decomposition error, and selects the best base gate type for each target unitary. In this mode success reports whether the selected decomposition meets target_fidelity in terms of \(F_u\).

target_unitary The 4x4 unitary to compile.
base_gates A single 4x4 base gate unitary, or a sequence of them. Each base gate must be entangling for arbitrary targets to be compilable.
target_fidelity Decomposition fidelity threshold. Layer growth stops once it is met; success in the result reports whether the returned decomposition meets it. Should be a float slightly below 1, e.g. 1 - 1e-8 (the default) for exact compilation or 0.99 for approximate. Required when hardware error rates are given: the threshold then applies to the overall fidelity $F_u = F_d \cdot F_h$.
max_layers Maximum number of base gate applications allowed.
base_gate_error_rates Optional hardware error rate of each base gate, one per entry of base_gates. When error rates are given, the compiler maximizes the overall fidelity \(F_u = F_d \cdot F_h\) over all (base gate, layer count) combinations instead of stopping at the first decomposition meeting target_fidelity.
single_qubit_error_rates Optional hardware error rate of each single-qubit gate, folded into the hardware fidelity \(F_h\). Either a single rate applied to both qubits, or a pair of rates (one per qubit the two-qubit gate acts on), e.g. from per-qubit calibration data.
num_restarts Number of random restarts of the BFGS optimizer per (base gate, layer count) pair. Higher values improve accuracy at the cost of runtime.
maxiter Maximum number of iterations of each BFGS run.
random_state Random state or seed used to generate the optimizer's starting points.

A TwoQubitNumericalCompilationResult with the best decomposition found.

ValueError If target_unitary is not a finite 4x4 unitary, base_gates is empty, malformed, or contains non-finite or non-unitary matrices, base_gate_error_rates does not match base_gates, target_fidelity is not set while hardware error rates are given, or target_fidelity, max_layers, num_restarts, maxiter, base_gate_error_rates or single_qubit_error_rates are out of range.