def _build_commutator_routine(params: List, operator: WeightedPauliOperator, z2_symmetries: Z2Symmetries, sign: int ) -> Tuple[int, int, WeightedPauliOperator, WeightedPauliOperator, WeightedPauliOperator, WeightedPauliOperator]: """Numerically computes the commutator / double commutator between operators. Args: params: list containing the indices of matrix element and the corresponding excitation operators operator: the hamiltonian z2_symmetries: z2_symmetries in case of tapering sign: commute or anticommute Returns: The indices of the matrix element and the corresponding qubit operator for each of the EOM matrices """ m_u, n_u, left_op, right_op_1, right_op_2 = params if left_op is None: q_mat_op = None w_mat_op = None m_mat_op = None v_mat_op = None else: if right_op_1 is None and right_op_2 is None: q_mat_op = None w_mat_op = None m_mat_op = None v_mat_op = None else: if right_op_1 is not None: q_mat_op = commutator(left_op, operator, right_op_1, sign=sign) w_mat_op = commutator(left_op, right_op_1, sign=sign) q_mat_op = None if q_mat_op.is_empty() else q_mat_op w_mat_op = None if w_mat_op.is_empty() else w_mat_op else: q_mat_op = None w_mat_op = None if right_op_2 is not None: m_mat_op = commutator(left_op, operator, right_op_2, sign=sign) v_mat_op = commutator(left_op, right_op_2, sign=sign) m_mat_op = None if m_mat_op.is_empty() else m_mat_op v_mat_op = None if v_mat_op.is_empty() else v_mat_op else: m_mat_op = None v_mat_op = None if not z2_symmetries.is_empty(): if q_mat_op is not None and not q_mat_op.is_empty(): q_mat_op = z2_symmetries.taper(q_mat_op) if w_mat_op is not None and not w_mat_op.is_empty(): w_mat_op = z2_symmetries.taper(w_mat_op) if m_mat_op is not None and not m_mat_op.is_empty(): m_mat_op = z2_symmetries.taper(m_mat_op) if v_mat_op is not None and not v_mat_op.is_empty(): v_mat_op = z2_symmetries.taper(v_mat_op) return m_u, n_u, q_mat_op, w_mat_op, m_mat_op, v_mat_op
def _build_commutator_rountine(params, operator, z2_symmetries): m_u, n_u, left_op, right_op_1, right_op_2 = params if left_op is None: q_mat_op = None w_mat_op = None m_mat_op = None v_mat_op = None else: if right_op_1 is None and right_op_2 is None: q_mat_op = None w_mat_op = None m_mat_op = None v_mat_op = None else: if right_op_1 is not None: q_mat_op = commutator(left_op, operator, right_op_1) w_mat_op = commutator(left_op, right_op_1) q_mat_op = None if q_mat_op.is_empty() else q_mat_op w_mat_op = None if w_mat_op.is_empty() else w_mat_op else: q_mat_op = None w_mat_op = None if right_op_2 is not None: m_mat_op = commutator(left_op, operator, right_op_2) v_mat_op = commutator(left_op, right_op_2) m_mat_op = None if m_mat_op.is_empty() else m_mat_op v_mat_op = None if v_mat_op.is_empty() else v_mat_op else: m_mat_op = None v_mat_op = None if not z2_symmetries.is_empty(): if q_mat_op is not None and not q_mat_op.is_empty(): q_mat_op = z2_symmetries.taper(q_mat_op) if w_mat_op is not None and not w_mat_op.is_empty(): w_mat_op = z2_symmetries.taper(w_mat_op) if m_mat_op is not None and not m_mat_op.is_empty(): m_mat_op = z2_symmetries.taper(m_mat_op) if v_mat_op is not None and not v_mat_op.is_empty(): v_mat_op = z2_symmetries.taper(v_mat_op) return m_u, n_u, q_mat_op, w_mat_op, m_mat_op, v_mat_op