def test_mapping_for_single_op(self):
        """Test for single register operator."""
        with self.subTest("test +"):
            op = FermionicOp("+", display_format="dense")
            expected = PauliSumOp.from_list([("X", 0.5), ("Y", -0.5j)])
            self.assertEqual(BravyiKitaevMapper().map(op), expected)

        with self.subTest("test -"):
            op = FermionicOp("-", display_format="dense")
            expected = PauliSumOp.from_list([("X", 0.5), ("Y", 0.5j)])
            self.assertEqual(BravyiKitaevMapper().map(op), expected)

        with self.subTest("test N"):
            op = FermionicOp("N", display_format="dense")
            expected = PauliSumOp.from_list([("I", 0.5), ("Z", -0.5)])
            self.assertEqual(BravyiKitaevMapper().map(op), expected)

        with self.subTest("test E"):
            op = FermionicOp("E", display_format="dense")
            expected = PauliSumOp.from_list([("I", 0.5), ("Z", 0.5)])
            self.assertEqual(BravyiKitaevMapper().map(op), expected)

        with self.subTest("test I"):
            op = FermionicOp("I", display_format="dense")
            expected = PauliSumOp.from_list([("I", 1)])
            self.assertEqual(BravyiKitaevMapper().map(op), expected)
    def test_mapping(self):
        """Test mapping to qubit operator"""
        driver = HDF5Driver(hdf5_input=self.get_resource_path(
            "test_driver_hdf5.hdf5", "drivers/second_quantization/hdf5d"))
        driver_result = driver.run()
        fermionic_op = driver_result.second_q_ops()["ElectronicEnergy"]
        mapper = BravyiKitaevMapper()
        qubit_op = mapper.map(fermionic_op)

        # Note: The PauliSumOp equals, as used in the test below, use the equals of the
        #       SparsePauliOp which in turn uses np.allclose() to determine equality of
        #       coeffs. So the reference operator above will be matched on that basis so
        #       we don't need to worry about tiny precision changes for any reason.

        self.assertEqual(qubit_op, TestBravyiKitaevMapper.REF_H2)
    def test_mapping(self):
        """ Test mapping to qubit operator """
        driver = HDF5Driver(hdf5_input=self.get_resource_path('test_driver_hdf5.hdf5',
                                                              'drivers/hdf5d'))
        q_molecule = driver.run()
        fermionic_op = fermionic_op_builder._build_fermionic_op(q_molecule)
        mapper = BravyiKitaevMapper()
        qubit_op = mapper.map(fermionic_op)

        # Note: The PauliSumOp equals, as used in the test below, use the equals of the
        #       SparsePauliOp which in turn uses np.allclose() to determine equality of
        #       coeffs. So the reference operator above will be matched on that basis so
        #       we don't need to worry about tiny precision changes for any reason.

        self.assertEqual(qubit_op, TestBravyiKitaevMapper.REF_H2)
 def test_unsupported_mapper(self):
     """Test passing unsupported mapper fails gracefully."""
     with self.assertRaisesRegex(NotImplementedError, "supported"):
         _ = FermionicGaussianState(
             np.block([np.eye(2), np.zeros((2, 2))]),
             qubit_converter=QubitConverter(BravyiKitaevMapper()),
         )
 def test_oh_uhf_bk(self):
     """ oh uhf bk test """
     driver = PySCFDriver(atom=self.o_h, unit=UnitsType.ANGSTROM,
                          charge=0, spin=1, basis='sto-3g',
                          hf_method=HFMethodType.UHF)
     result = self._run_driver(driver,
                               converter=QubitConverter(BravyiKitaevMapper()))
     self._assert_energy_and_dipole(result, 'oh')
 def test_vqe_mes_bk_auto(self):
     """Test VQEUCCSDFactory with QEOM + Bravyi-Kitaev mapping + auto symmetry"""
     self.skipTest(
         "Temporarily skip test until the changes done by "
         "https://github.com/Qiskit/qiskit-terra/pull/7551 are handled properly."
     )
     converter = QubitConverter(BravyiKitaevMapper(),
                                z2symmetry_reduction="auto")
     self._solve_with_vqe_mes(converter)
 def test_lih_rhf_bk(self):
     """ lih rhf bk test """
     driver = PySCFDriver(atom=self.lih, unit=UnitsType.ANGSTROM,
                          charge=0, spin=0, basis='sto-3g',
                          hf_method=HFMethodType.RHF)
     result = self._run_driver(driver,
                               converter=QubitConverter(BravyiKitaevMapper()),
                               transformers=[FreezeCoreTransformer()])
     self._assert_energy_and_dipole(result, 'lih')
 def test_oh_rohf_bk(self):
     """oh rohf bk test"""
     driver = PySCFDriver(
         atom=self.o_h,
         unit=UnitsType.ANGSTROM,
         charge=0,
         spin=1,
         basis="sto-3g",
         method=MethodType.ROHF,
     )
     result = self._run_driver(driver,
                               converter=QubitConverter(
                                   BravyiKitaevMapper()))
     self._assert_energy_and_dipole(result, "oh")
 def test_unsupported_mapper(self):
     """Test passing unsupported mapper fails gracefully."""
     with self.assertRaisesRegex(NotImplementedError, "supported"):
         _ = BogoliubovTransform(np.eye(2),
                                 qubit_converter=QubitConverter(
                                     BravyiKitaevMapper()))
示例#10
0
 def test_qubits_4_bk_h2(self):
     """ qubits 4 bk h2 test """
     state = HartreeFock(4, (1, 1), QubitConverter(BravyiKitaevMapper()))
     ref = QuantumCircuit(4)
     ref.x([0, 1, 2])
     self.assertEqual(state, ref)
 def test_allows_two_qubit_reduction(self):
     """Test this returns False for this mapper"""
     mapper = BravyiKitaevMapper()
     self.assertFalse(mapper.allows_two_qubit_reduction)
 def test_vqe_mes_bk(self):
     """Test VQEUCCSDFactory with QEOM + Bravyi-Kitaev mapping"""
     converter = QubitConverter(BravyiKitaevMapper())
     self._solve_with_vqe_mes(converter)
示例#13
0
 def test_vqe_mes_bk_auto(self):
     """Test VQEUCCSDFactory with QEOM + Bravyi-Kitaev mapping + auto symmetry"""
     converter = QubitConverter(BravyiKitaevMapper(),
                                z2symmetry_reduction="auto")
     self._solve_with_vqe_mes(converter)