Пример #1
0
 def test_set_optimizer_to_none(self):
     """Tests that setting the optimizer to None results in the default behavior"""
     vqe = VQE(
         ansatz=self.ryrz_wavefunction,
         optimizer=L_BFGS_B(),
         quantum_instance=self.statevector_simulator,
     )
     vqe.optimizer = None
     self.assertIsInstance(vqe.optimizer, SLSQP)
Пример #2
0
    def test_vqe_optimizer(self):
        """Test running same VQE twice to re-use optimizer, then switch optimizer"""
        vqe = VQE(
            optimizer=SLSQP(),
            quantum_instance=QuantumInstance(BasicAer.get_backend("statevector_simulator")),
        )

        def run_check():
            result = vqe.compute_minimum_eigenvalue(operator=self.h2_op)
            self.assertAlmostEqual(result.eigenvalue.real, -1.85727503, places=5)

        run_check()

        with self.subTest("Optimizer re-use"):
            run_check()

        with self.subTest("Optimizer replace"):
            vqe.optimizer = L_BFGS_B()
            run_check()