def test_resize(self):
        """Test resizing the Random Pauli circuit preserves the gates."""
        circuit = PauliTwoDesign(1)
        top_gates = [op.name for op, _, _ in circuit.decompose().data]

        circuit.num_qubits = 3
        decomposed = circuit.decompose()
        with self.subTest("assert existing gates remain"):
            new_top_gates = []
            for op, qargs, _ in decomposed:
                if qargs == [decomposed.qubits[0]]:  # if top qubit
                    new_top_gates.append(op.name)

            self.assertEqual(top_gates, new_top_gates)
    def test_random_pauli(self):
        """Test the Random Pauli circuit."""
        circuit = PauliTwoDesign(4, seed=12, reps=1)

        qr = QuantumRegister(4, "q")
        params = circuit.ordered_parameters

        # expected circuit for the random seed 12
        expected = QuantumCircuit(qr)

        # initial RYs
        expected.ry(np.pi / 4, qr)

        # first random Pauli layer
        expected.ry(params[0], 0)
        expected.rx(params[1], 1)
        expected.rz(params[2], 2)
        expected.rz(params[3], 3)

        # entanglement
        expected.cz(0, 1)
        expected.cz(2, 3)
        expected.cz(1, 2)

        # second random Pauli layer
        expected.rx(params[4], 0)
        expected.rx(params[5], 1)
        expected.rx(params[6], 2)
        expected.rx(params[7], 3)

        self.assertEqual(circuit.decompose(), expected)
    def test_resize(self):
        """Test resizing the Random Pauli circuit preserves the gates."""
        circuit = PauliTwoDesign(1)
        top_gates = [
            instruction.operation.name
            for instruction in circuit.decompose().data
        ]

        circuit.num_qubits = 3
        decomposed = circuit.decompose()
        with self.subTest("assert existing gates remain"):
            new_top_gates = []
            for instruction in decomposed:
                if instruction.qubits == (
                        decomposed.qubits[0], ):  # if top qubit
                    new_top_gates.append(instruction.operation.name)

            self.assertEqual(top_gates, new_top_gates)
    def test_random_pauli(self):
        """Test the Random Pauli circuit."""
        circuit = PauliTwoDesign(4, seed=12, reps=1)

        qr = QuantumRegister(4, "q")
        params = circuit.ordered_parameters

        # expected circuit for the random seed 12
        #
        #      ┌─────────┐┌──────────┐   ┌──────────┐
        # q_0: ┤ Ry(π/4) ├┤ Ry(θ[0]) ├─■─┤ Rx(θ[4]) ├────────────
        #      ├─────────┤├──────────┤ │ └──────────┘┌──────────┐
        # q_1: ┤ Ry(π/4) ├┤ Rx(θ[1]) ├─■──────■──────┤ Rx(θ[5]) ├
        #      ├─────────┤├──────────┤        │      ├──────────┤
        # q_2: ┤ Ry(π/4) ├┤ Rz(θ[2]) ├─■──────■──────┤ Rx(θ[6]) ├
        #      ├─────────┤├──────────┤ │ ┌──────────┐└──────────┘
        # q_3: ┤ Ry(π/4) ├┤ Rz(θ[3]) ├─■─┤ Rx(θ[7]) ├────────────
        #      └─────────┘└──────────┘   └──────────┘
        expected = QuantumCircuit(qr)

        # initial RYs
        expected.ry(np.pi / 4, qr)

        # first random Pauli layer
        expected.ry(params[0], 0)
        expected.rx(params[1], 1)
        expected.rz(params[2], 2)
        expected.rz(params[3], 3)

        # entanglement
        expected.cz(0, 1)
        expected.cz(2, 3)
        expected.cz(1, 2)

        # second random Pauli layer
        expected.rx(params[4], 0)
        expected.rx(params[5], 1)
        expected.rx(params[6], 2)
        expected.rx(params[7], 3)

        self.assertEqual(circuit.decompose(), expected)