def test_tapering_qubits_manual_input(self):
        """
        Test taper_off_qubits function using LiH Hamiltonian.

        Checks different qubits inputs to remove manually.

        Test the lowest eigenvalue against the full Hamiltonian,
        and the full spectrum between them.
        """
        hamiltonian, spectrum = lih_hamiltonian()
        qubit_hamiltonian = jordan_wigner(hamiltonian)
        stab1 = QubitOperator('Z0 Z2', -1.0)
        stab2 = QubitOperator('Z1 Z3', -1.0)

        tapered_ham_0_3 = taper_off_qubits(qubit_hamiltonian, [stab1, stab2],
                                           manual_input=True,
                                           fixed_positions=[0, 3])
        tapered_ham_2_1 = taper_off_qubits(qubit_hamiltonian, [stab1, stab2],
                                           manual_input=True,
                                           fixed_positions=[2, 1])

        tapered_spectrum_0_3 = eigenspectrum(tapered_ham_0_3)
        tapered_spectrum_2_1 = eigenspectrum(tapered_ham_2_1)

        self.assertAlmostEqual(spectrum[0], tapered_spectrum_0_3[0])
        self.assertAlmostEqual(spectrum[0], tapered_spectrum_2_1[0])
        self.assertTrue(
            numpy.allclose(tapered_spectrum_0_3, tapered_spectrum_2_1))
    def test_tappering_stabilizer_more_qubits(self):
        """Test for stabilizer with more qubits than operator."""
        hamiltonian = QubitOperator('Y0 Y1', 1.0)
        stab = QubitOperator('X0 X1 X2', -1.0)

        num_qubits = max(count_qubits(hamiltonian), count_qubits(stab))
        tap_ham = taper_off_qubits(hamiltonian, stab)
        num_qubits_tap = count_qubits(tap_ham)

        self.assertFalse(num_qubits == num_qubits_tap)

        hamiltonian = QubitOperator('X0 X1', 1.0)
        stab = QubitOperator('Y0 Y1 Y2', -1.0)

        num_qubits = max(count_qubits(hamiltonian), count_qubits(stab))
        tap_ham = taper_off_qubits(hamiltonian, stab)
        num_qubits_tap = count_qubits(tap_ham)
        self.assertFalse(num_qubits == num_qubits_tap)
    def test_tapering_qubits_manual_input_false(self):
        """Test taper_off_qubits function using LiH Hamiltonian."""
        hamiltonian, spectrum = lih_hamiltonian()
        qubit_hamiltonian = jordan_wigner(hamiltonian)
        stab1 = QubitOperator('Z0 Z2', -1.0)
        stab2 = QubitOperator('Z1 Z3', -1.0)

        tapered_hamiltonian = taper_off_qubits(operator=qubit_hamiltonian,
                                               stabilizers=[stab1, stab2],
                                               manual_input=False,
                                               fixed_positions=[0, 3])
        tapered_spectrum = eigenspectrum(tapered_hamiltonian)

        self.assertAlmostEqual(spectrum[0], tapered_spectrum[0])