Pitt-JonesLab / slam_decomposition

Numerical optimizers for decomposing unitary ops, or Hamiltonian parameter sweeping
MIT License
4 stars 1 forks source link

Recursive Family Check Mixed Basis #14

Closed evmckinney9 closed 1 year ago

evmckinney9 commented 1 year ago

Currently, there exists a stop condition, if sibling is longer than a full iSwap then stop.

# construct the older sibling, based on parity of ki
    if ki % 2 == 0:
        rec_iter_factor = 2
    else:
        rec_iter_factor = 3
    sib_basis_factor = rec_iter_factor * basis_factor
    older_sibling = ConversionGainGate(*child_gate.params[:-1], t_el=child_gate.params[-1] * rec_iter_factor)
    #TODO need to set a duration attribute here
    older_sibling.normalize_duration(1)

    # stop condition, if sibling is bigger than iswap
    #TODO, what we can check is a mixed basis (e.g. rather than 3 sqiswaps becoming 1.5 iswap and fail, make it 1 iswap and 1 sqiswap)
    if older_sibling.params[2] + older_sibling.params[3] <= np.pi/2:
        #new basis using older sibling
        sibling_basis = MixedOrderBasisCircuitTemplate(base_gates=[older_sibling], chatty_build=False, use_smush_polytope=use_smush)
        sibling_decomp, sib_score = recursive_sibling_check(sibling_basis, target_u, use_smush=use_smush, basis_factor=sib_basis_factor, rec_iter_factor=rec_iter_factor, cost_1q=cost_1q)
    else:
        sib_score = np.inf

The idea behind this parity condition, is that we are trying to discover the oldest sibling decomp in either 2 or 3 steps. However, we are missing the in-between case, which is when the oldest sibling does decomp in 1.5 or 2.5 steps. Let's focus on the 1.5 step because this case is used in the SWAP optimization for sqiswap basis.

Example: to optimize SWAP using sqiswap, we need parallel-drive iSwap to go to (0.5, 0.25, 0.25), then finish with 1 more sqiswap. If we inspect the SWAP, sqiswap decomp and go to the rec_iter_factor=3 case, we miss this because iswap(1.5) does not go to SWAP.

evmckinney9 commented 1 year ago

This is fairly trivial via inspection, but hard to programmatically generalize. For now, move to wontfix. Note, this means that QV (or non CX/SWAP gates) are potentially nonoptimized in the basis sqiswap sub pass