def test_h4ring_vqe_uccsd_microsoft_qsharp_size1(self): """ DMET on H4 ring with fragment size one, using VQE-UCCSD backend from Microsoft. """ mol = gto.Mole() mol.atom = H4_RING mol.basis = "minao" mol.charge = 0 mol.spin = 0 mol.build() # Initialize VQE object with MicrosoftQSharp backend from openqemist.quantum_solvers import MicrosoftQSharpParametricSolver from openqemist.electronic_structure_solvers import VQESolver vqe = VQESolver() vqe.hardware_backend_type = MicrosoftQSharpParametricSolver vqe.ansatz_type = MicrosoftQSharpParametricSolver.Ansatze.UCCSD # Run DMET dmet = DMETProblemDecomposition() dmet.electron_localization_method = meta_lowdin_localization dmet.electronic_structure_solver = vqe energy_vqe = dmet.simulate(mol, [1, 1, 1, 1]) self.assertAlmostEqual(energy_vqe, -1.9916120594, delta=1e-3)
def test_h4ring_vqe_uccsd_qiskit_size2(self): """ DMET on H4 ring with fragment size two, using VQE-UCCSD backend from Qiskit. """ mol = gto.Mole() mol.atom = H4_RING mol.basis = "minao" mol.charge = 0 mol.spin = 0 mol.build() # Initialize VQE object with Qiskit backend vqe = VQESolver() vqe.hardware_backend_type = QiskitParametricSolver vqe.ansatz_type = QiskitParametricSolver.Ansatze.UCCSD # Run DMET dmet = DMETProblemDecomposition() dmet.electron_localization_method = meta_lowdin_localization dmet.electronic_structure_solver = vqe energy_vqe = dmet.simulate(mol, [2, 2]) self.assertAlmostEqual(energy_vqe, -1.9916120594, delta=1e-3)
def test_get_rdm_no_sim(self): """Tests that exception is raised when calling `get_rdm` before `simulate` """ solver = VQESolver() solver.hardware_backend_type = MockQuantumSolver solver.ansatz_type = MockQuantumSolver.Ansatze.UCCSD self.assertRaises(RuntimeError, solver.get_rdm)
def test_h2_sto3g(self): """ Test the converged energye of VQE """ mol = gto.Mole() mol.atom = H2 mol.basis = "sto-3g" mol.charge = 0 mol.spin = 0 mol.build() solver = VQESolver() solver.hardware_backend_type = RigettiParametricSolver solver.ansatz_type = RigettiParametricSolver.Ansatze.UCCSD energy = solver.simulate(mol) self.assertAlmostEqual(energy, -1.1372704178510415, delta=1e-3)
def test_h4_sto3g(self): """ Test the converged energy of VQE with initial variational parameters provided by the user """ mol = gto.Mole() mol.atom = H4 mol.basis = "sto3g" mol.charge = 0 mol.spin = 0 mol.build() solver = VQESolver() solver.hardware_backend_type = QiskitParametricSolver solver.ansatz_type = QiskitParametricSolver.Ansatze.UCCSD energy = solver.simulate(mol) self.assertAlmostEqual(energy, -1.97784, delta=1e-3)
def test_lih_sto3g(self): """ Test the converged energie of VQE """ mol = gto.Mole() mol.atom = LiH mol.basis = "sto-3g" mol.charge = 0 mol.spin = 0 mol.build() solver = VQESolver() solver.hardware_backend_type = RigettiParametricSolver solver.ansatz_type = RigettiParametricSolver.Ansatze.UCCSD energy = solver.simulate(mol) self.assertAlmostEqual(energy, -7.78445501, delta=1e-3) print("LiH optimal energy :: ", energy)
def test_lih_sto3g(self): from openqemist.quantum_solvers import MicrosoftQSharpParametricSolver mol = gto.Mole() mol.atom = LiH mol.basis = "sto-3g" mol.charge = 0 mol.spin = 0 mol.build() solver = VQESolver() solver.hardware_backend_type = MicrosoftQSharpParametricSolver solver.ansatz_type = MicrosoftQSharpParametricSolver.Ansatze.UCCSD #solver.optimizer = energy = solver.simulate(mol) self.assertAlmostEqual(energy, -7.881855622231621, delta=1e-3)
def test_h2_sto3g(self): from openqemist.quantum_solvers import MicrosoftQSharpParametricSolver mol = gto.Mole() mol.atom = H2 mol.basis = "sto-3g" mol.charge = 0 mol.spin = 0 mol.build() solver = VQESolver() solver.hardware_backend_type = MicrosoftQSharpParametricSolver solver.ansatz_type = MicrosoftQSharpParametricSolver.Ansatze.UCCSD energy = solver.simulate(mol) self.assertAlmostEqual(energy, -1.1372704178510415, delta=1e-3)
def test_h2_321g(self): from openqemist.quantum_solvers import MicrosoftQSharpParametricSolver mol = gto.Mole() mol.atom = H2 mol.basis = "3-21g" mol.charge = 0 mol.spin = 0 mol.build() solver = VQESolver() solver.hardware_backend_type = MicrosoftQSharpParametricSolver solver.ansatz_type = MicrosoftQSharpParametricSolver.Ansatze.UCCSD #solver.optimizer = energy = solver.simulate(mol) self.assertAlmostEqual(energy, -1.1478300615818977, places=3)
def test_h4_sto3g(self): from openqemist.quantum_solvers import MicrosoftQSharpParametricSolver mol = gto.Mole() mol.atom = H4 mol.basis = "sto-3g" mol.charge = 0 mol.spin = 0 mol.build() solver = VQESolver() solver.hardware_backend_type = MicrosoftQSharpParametricSolver solver.ansatz_type = MicrosoftQSharpParametricSolver.Ansatze.UCCSD energy = solver.simulate(mol) # FCI is -1.9786006610379836, however VQE UCCSD seems to converge to # -1.9778376625571703 for several backends and optimizers, # which is still within chemical accuracy self.assertAlmostEqual(energy, -1.9786006610379836, delta=1e-3)
def test_mock(self): """ Test that the solver returns with the default optimizer from scipy. Since simlate is always returning the same number, this should force the optimizer to converge. """ mol = gto.Mole() mol.atom = H2 mol.basis = "sto-3g" mol.charge = 0 mol.spin = 0 mol.build() solver = VQESolver() solver.hardware_backend_type = MockQuantumSolver solver.ansatz_type = MockQuantumSolver.Ansatze.UCCSD energy = solver.simulate(mol) self.assertEqual(energy, 3)
def test_be_no_mf_default_optimizer(self): """ Test that the solver returns with the default optimizer from scipy. Since simlate is always returning the same number, this should force the optimizer to converge. """ mol = gto.Mole() mol.atom = Be mol.basis = "3-21g" mol.charge = 0 mol.spin = 0 mol.build() solver = VQESolver() solver.hardware_backend_type = MockQuantumSolver solver.ansatz_type = MockQuantumSolver.Ansatze.UCCSD energy = solver.simulate(mol) # The converged energy value should be what the mock solver returned at # the simulation call. self.assertEqual(energy, 3)
def test_h2_321g(self): """ Test the converged energye of VQE """ mol = gto.Mole() mol.atom = H2 mol.basis = "3-21g" mol.charge = 0 mol.spin = 0 mol.build() solver = VQESolver() solver.hardware_backend_type = RigettiParametricSolver solver.ansatz_type = RigettiParametricSolver.Ansatze.UCCSD solver.initial_var_params = [ -0.003013364325590502, 0.005694780930328863, 0.00035386539723315964, 0.04244748156400211, 0.02380828037656643, 0.018789486618923344, 0.0007322518664444671, 0.04376425859874745, 8.503425743572844e-05 ] energy = solver.simulate(mol) self.assertAlmostEqual(energy, -1.1478300615818977, delta=1e-3)
def test_h2_321g(self): """ Test the converged energy of VQE with initial variational parameters provided by the user """ mol = gto.Mole() mol.atom = H2 mol.basis = "3-21g" mol.charge = 0 mol.spin = 0 mol.build() solver = VQESolver() solver.hardware_backend_type = QiskitParametricSolver solver.ansatz_type = QiskitParametricSolver.Ansatze.UCCSD solver.initial_var_params = [ -0.01039529, -0.04685435, -0.01858744, -0.01118045, -0.04674074, -0.01848484, -0.12702138, -0.0222594, 0.04799664, -0.02237422, -0.04972733, 0.01266251, 0.04764409, 0.01265669, -0.06169727 ] energy = solver.simulate(mol) self.assertAlmostEqual(energy, -1.1478300615818977, delta=1e-3)