def __init__(self,
                 kak_basis_gate=None,
                 force_consolidate=False,
                 basis_gates=None):
        """ConsolidateBlocks initializer.

        Args:
            kak_basis_gate (Gate): Basis gate for KAK decomposition.
            force_consolidate (bool): Force block consolidation
            basis_gates (List(str)): Basis gates from which to choose a KAK gate.
        """
        super().__init__()
        self.basis_gates = basis_gates
        self.force_consolidate = force_consolidate

        if kak_basis_gate is not None:
            self.decomposer = TwoQubitBasisDecomposer(kak_basis_gate)
        elif basis_gates is not None:
            kak_basis_gate = unitary_synthesis._choose_kak_gate(basis_gates)
            if kak_basis_gate is not None:
                self.decomposer = TwoQubitBasisDecomposer(kak_basis_gate)
            else:
                self.decomposer = None
        else:
            self.decomposer = TwoQubitBasisDecomposer(CXGate())
예제 #2
0
    def __init__(self,
                 kak_basis_gate=None,
                 force_consolidate=False,
                 basis_gates=None,
                 target=None):
        """ConsolidateBlocks initializer.

        Args:
            kak_basis_gate (Gate): Basis gate for KAK decomposition.
            force_consolidate (bool): Force block consolidation
            basis_gates (List(str)): Basis gates from which to choose a KAK gate.
            target (Target): The target object for the compilation target backend
        """
        super().__init__()
        self.basis_gates = None
        self.target = target
        if basis_gates is not None:
            self.basis_gates = set(basis_gates)
        self.force_consolidate = force_consolidate

        if kak_basis_gate is not None:
            self.decomposer = TwoQubitBasisDecomposer(kak_basis_gate)
        elif basis_gates is not None:
            self.decomposer = unitary_synthesis._basis_gates_to_decomposer_2q(
                basis_gates)
        else:
            self.decomposer = TwoQubitBasisDecomposer(CXGate())
예제 #3
0
    def test_exact_supercontrolled_decompose_random(self, nsamples=100):
        """Verify exact decomposition for random supercontrolled basis and random target"""

        for _ in range(nsamples):
            k1 = np.kron(random_unitary(2).data, random_unitary(2).data)
            k2 = np.kron(random_unitary(2).data, random_unitary(2).data)
            basis_unitary = k1 @ Ud(np.pi/4, 0, 0) @ k2
            decomposer = TwoQubitBasisDecomposer(UnitaryGate(basis_unitary))
            self.check_exact_decomposition(random_unitary(4).data, decomposer)
예제 #4
0
 def __init__(self, kak_basis_gate=CnotGate(), force_consolidate=False):
     """
     Args:
         kak_basis_gate (Gate): Basis gate for KAK decomposition.
         force_consolidate (bool): Force block consolidation
     """
     super().__init__()
     self.force_consolidate = force_consolidate
     self.decomposer = TwoQubitBasisDecomposer(kak_basis_gate)
예제 #5
0
    def __init__(self, kak_basis_gate=CXGate(), force_consolidate=False):
        """ConsolidateBlocks initializer.

        Args:
            kak_basis_gate (Gate): Basis gate for KAK decomposition.
            force_consolidate (bool): Force block consolidation
        """
        super().__init__()
        self.force_consolidate = force_consolidate
        if kak_basis_gate is not None:
            self.decomposer = TwoQubitBasisDecomposer(kak_basis_gate)
        else:
            self.decomposer = None
예제 #6
0
 def test_exact_nonsupercontrolled_decompose(self):
     """Check that the nonsupercontrolled basis throws a warning"""
     with self.assertWarns(UserWarning, msg="Supposed to warn when basis non-supercontrolled"):
         TwoQubitBasisDecomposer(UnitaryGate(Ud(np.pi/4, 0.2, 0.1)))