def setUp(self): super().setUp() self.reference_energy = 2539.259482550559 basis = [2, 2, 2, 2] # 4 modes and 2 modals per mode self.bos_op = BosonicOperator(self.CO2_B3LYP_ccpVDZ_4MODES_2MODALS, basis)
def setUp(self): super().setUp() self.reference_energy = 2536.4879763624226 self.basis = [2, 2, 2, 2] # 4 modes and 2 modals per mode self.bos_op = BosonicOperator(self.CO2_B3LYP_ccpVDZ_4MODES_2MODALS, self.basis)
def test_chc_vscf(self): """ chc vscf test """ co2_2modes_2modals_2body = [ [[[[0, 0, 0]], 320.8467332810141], [[[0, 1, 1]], 1760.878530705873], [[[1, 0, 0]], 342.8218290247543], [[[1, 1, 1]], 1032.396323618631]], [[[[0, 0, 0], [1, 0, 0]], -57.34003649795117], [[[0, 0, 1], [1, 0, 0]], -56.33205925807966], [[[0, 1, 0], [1, 0, 0]], -56.33205925807966], [[[0, 1, 1], [1, 0, 0]], -60.13032761856809], [[[0, 0, 0], [1, 0, 1]], -65.09576309934431], [[[0, 0, 1], [1, 0, 1]], -62.2363839133389], [[[0, 1, 0], [1, 0, 1]], -62.2363839133389], [[[0, 1, 1], [1, 0, 1]], -121.5533969109279], [[[0, 0, 0], [1, 1, 0]], -65.09576309934431], [[[0, 0, 1], [1, 1, 0]], -62.2363839133389], [[[0, 1, 0], [1, 1, 0]], -62.2363839133389], [[[0, 1, 1], [1, 1, 0]], -121.5533969109279], [[[0, 0, 0], [1, 1, 1]], -170.744837386338], [[[0, 0, 1], [1, 1, 1]], -167.7433236025723], [[[0, 1, 0], [1, 1, 1]], -167.7433236025723], [[[0, 1, 1], [1, 1, 1]], -179.0536532281924]] ] basis = [2, 2] bosonic_op = BosonicOperator(co2_2modes_2modals_2body, basis) qubit_op = bosonic_op.mapping('direct', threshold=1e-5) init_state = VSCF(basis) num_qubits = sum(basis) uvcc_varform = UVCC(num_qubits, basis, [0, 1]) excitations = uvcc_varform.excitations_in_qubit_format() chc_varform = CHC(num_qubits, ladder=False, excitations=excitations, initial_state=init_state) backend = QuantumInstance( BasicAer.get_backend('statevector_simulator'), seed_transpiler=2, seed_simulator=2) optimizer = COBYLA(maxiter=1000) algo = VQE(qubit_op, chc_varform, optimizer) vqe_result = algo.run(backend) energy = vqe_result['optimal_value'] self.assertAlmostEqual(energy, self.reference_energy, places=4)
def test_harmonic_basis(self): """test for obtaining the hamiltonian in the harmonic basis""" num_modals = 2 hamiltonian_in_harmonic_basis = \ self.gaussian_log_data.compute_harmonic_modes(num_modals, truncation_order=2) basis = [num_modals, num_modals, num_modals, num_modals] # 4 modes and 2 modals per mode bos_op = BosonicOperator(hamiltonian_in_harmonic_basis, basis) qubit_op = bos_op.mapping('direct', threshold=1e-5) algo = NumPyEigensolver(qubit_op, k=100) result = algo.run() vecs = result['eigenstates'] energies = result['eigenvalues'] gs_energy = bos_op.ground_state_energy(vecs, energies) self.assertAlmostEqual(gs_energy, self.reference_energy, places=6)
class TestBosonicOperator(QiskitChemistryTestCase): """Bosonic Operator tests.""" CO2_B3LYP_ccpVDZ_4MODES_2MODALS = [ [[[[0, 0, 0]], 1215.682529375], [[[0, 1, 1]], 3656.9551768750007], [[[1, 0, 0]], 682.5053337500001], [[[1, 0, 1]], -46.77167173323271], [[[1, 1, 0]], -46.77167173323271], [[[1, 1, 1]], 2050.1464387500005], [[[2, 0, 0]], 329.41209562500006], [[[2, 1, 1]], 992.0224281250003], [[[3, 0, 0]], 328.12046812500006], [[[3, 1, 1]], 985.5642906250002]], [[[[1, 0, 0], [0, 0, 0]], 5.039653750000002], [[[1, 0, 0], [0, 1, 1]], 15.118961250000009], [[[1, 0, 1], [0, 0, 0]], -89.0908653064951], [[[1, 0, 1], [0, 1, 1]], -267.27259591948535], [[[1, 1, 0], [0, 0, 0]], -89.0908653064951], [[[1, 1, 0], [0, 1, 1]], -267.27259591948535], [[[1, 1, 1], [0, 0, 0]], 15.118961250000009], [[[1, 1, 1], [0, 1, 1]], 45.35688375000003], [[[2, 0, 0], [0, 0, 0]], -6.3850425000000035], [[[2, 0, 0], [0, 1, 1]], -19.15512750000001], [[[2, 0, 0], [1, 0, 0]], -2.5657231250000008], [[[2, 0, 0], [1, 0, 1]], 21.644966371722845], [[[2, 0, 0], [1, 1, 0]], 21.644966371722845], [[[2, 0, 0], [1, 1, 1]], -7.697169375000003], [[[2, 0, 1], [0, 0, 1]], -2.0085637500000004], [[[2, 0, 1], [0, 1, 0]], -2.0085637500000004], [[[2, 1, 0], [0, 0, 1]], -2.0085637500000004], [[[2, 1, 0], [0, 1, 0]], -2.0085637500000004], [[[2, 1, 1], [0, 0, 0]], -19.15512750000001], [[[2, 1, 1], [0, 1, 1]], -57.46538250000003], [[[2, 1, 1], [1, 0, 0]], -7.697169375000004], [[[2, 1, 1], [1, 0, 1]], 64.93489911516855], [[[2, 1, 1], [1, 1, 0]], 64.93489911516855], [[[2, 1, 1], [1, 1, 1]], -23.091508125000015], [[[3, 0, 0], [0, 0, 0]], -4.595841875000001], [[[3, 0, 0], [0, 1, 1]], -13.787525625000006], [[[3, 0, 0], [1, 0, 0]], -1.683979375000001], [[[3, 0, 0], [1, 0, 1]], 6.412754934114709], [[[3, 0, 0], [1, 1, 0]], 6.412754934114709], [[[3, 0, 0], [1, 1, 1]], -5.051938125000003], [[[3, 0, 0], [2, 0, 0]], -0.5510218750000002], [[[3, 0, 0], [2, 1, 1]], -1.6530656250000009], [[[3, 0, 1], [0, 0, 1]], 3.5921675000000004], [[[3, 0, 1], [0, 1, 0]], 3.5921675000000004], [[[3, 0, 1], [2, 0, 1]], 7.946551250000004], [[[3, 0, 1], [2, 1, 0]], 7.946551250000004], [[[3, 1, 0], [0, 0, 1]], 3.5921675000000004], [[[3, 1, 0], [0, 1, 0]], 3.5921675000000004], [[[3, 1, 0], [2, 0, 1]], 7.946551250000004], [[[3, 1, 0], [2, 1, 0]], 7.946551250000004], [[[3, 1, 1], [0, 0, 0]], -13.787525625000006], [[[3, 1, 1], [0, 1, 1]], -41.362576875000016], [[[3, 1, 1], [1, 0, 0]], -5.051938125000002], [[[3, 1, 1], [1, 0, 1]], 19.238264802344126], [[[3, 1, 1], [1, 1, 0]], 19.238264802344126], [[[3, 1, 1], [1, 1, 1]], -15.15581437500001], [[[3, 1, 1], [2, 0, 0]], -1.6530656250000009], [[[3, 1, 1], [2, 1, 1]], -4.959196875000003]] ] def setUp(self): super().setUp() self.reference_energy = 2539.259482550559 basis = [2, 2, 2, 2] # 4 modes and 2 modals per mode self.bos_op = BosonicOperator(self.CO2_B3LYP_ccpVDZ_4MODES_2MODALS, basis) def test_mapping(self): """ mapping test """ qubit_op = self.bos_op.mapping('direct', threshold=1e-5) algo = NumPyEigensolver(qubit_op, k=100) result = algo.run() vecs = result['eigenstates'] energies = result['eigenvalues'] gs_energy = self.bos_op.ground_state_energy(vecs, energies) self.assertAlmostEqual(gs_energy, self.reference_energy, places=4)