def test_second_q_ops_without_transformers(self): """Tests that the list of second quantized operators is created if no transformers provided.""" expected_num_of_sec_quant_ops = 5 logfile = self.get_resource_path( "CO2_freq_B3LYP_ccpVDZ.log", "problems/second_quantization/vibrational/resources", ) driver = GaussianForcesDriver(logfile=logfile) watson_hamiltonian = driver.run() num_modals = 2 truncation_order = 3 num_modes = watson_hamiltonian.num_modes num_modals = [num_modals] * num_modes vibrational_problem = VibrationalStructureProblem( driver, num_modals, truncation_order) second_quantized_ops = vibrational_problem.second_q_ops() vibrational_op = second_quantized_ops[0] with self.subTest( "Check expected length of the list of second quantized operators." ): assert len(second_quantized_ops) == expected_num_of_sec_quant_ops with self.subTest( "Check types in the list of second quantized operators."): assert isinstance(vibrational_op, VibrationalOp)
def test_driver_logfile(self): """ Test the driver works with logfile (Gaussian does not need to be installed) """ driver = GaussianForcesDriver(logfile=self.get_resource_path( 'test_driver_gaussian_log.txt', 'drivers/gaussiand')) result = driver.run() self._check_driver_result(result)
def test_driver_logfile(self): """Test the driver works with logfile (Gaussian does not need to be installed)""" driver = GaussianForcesDriver(logfile=self.get_resource_path( "test_driver_gaussian_log.txt", "drivers/second_quantization/gaussiand")) result = driver.run() self._check_driver_result(result)
def test_driver_jcf(self): """ Test the driver works with job control file """ try: driver = GaussianForcesDriver([ '#p B3LYP/6-31g Freq=(Anharm) Int=Ultrafine SCF=VeryTight', '', 'CO2 geometry optimization B3LYP/6-31g', '', '0 1', 'C -0.848629 2.067624 0.160992', 'O 0.098816 2.655801 -0.159738', 'O -1.796073 1.479446 0.481721', '', '' ]) result = driver.run() self._check_driver_result(result) except QiskitNatureError: self.skipTest('GAUSSIAN driver does not appear to be installed')
def test_driver_molecule(self): """ Test the driver works with Molecule """ try: driver = GaussianForcesDriver(molecule=Molecule(geometry=[ ('C', [-0.848629, 2.067624, 0.160992]), ('O', [0.098816, 2.655801, -0.159738]), ('O', [-1.796073, 1.479446, 0.481721]) ], multiplicity=1, charge=0), basis='6-31g') result = driver.run() self._check_driver_result(result) except QiskitNatureError: self.skipTest('GAUSSIAN driver does not appear to be installed')
def test_create_labels(self): """Tests that correct labels are built.""" logfile = self.get_resource_path( 'CO2_freq_B3LYP_ccpVDZ.log', 'problems/second_quantization/vibrational/resources') driver = GaussianForcesDriver(logfile=logfile) watson_hamiltonian = driver.run() num_modals = 2 truncation_order = 3 num_modes = watson_hamiltonian.num_modes num_modals = [num_modals] * num_modes boson_hamilt_harm_basis = HarmonicBasis(watson_hamiltonian, num_modals, truncation_order).convert() labels, coeffs = zip(*_create_labels(boson_hamilt_harm_basis)) self.assertSetEqual(frozenset(labels), frozenset(expected_labels)) self.assertSetEqual(frozenset(coeffs), frozenset(expected_coeffs))
def test_vibrational_op_builder(self): """Tests that a VibrationalOp is created correctly from a driver.""" logfile = self.get_resource_path( 'CO2_freq_B3LYP_ccpVDZ.log', 'problems/second_quantization/vibrational/resources' ) driver = GaussianForcesDriver(logfile=logfile) watson_hamiltonian = driver.run() num_modals = 2 truncation_order = 3 vibrational_op = _build_vibrational_op(watson_hamiltonian, num_modals, truncation_order) assert isinstance(vibrational_op, VibrationalOp) labels, coeffs = zip(*vibrational_op.to_list()) self.assertSetEqual(frozenset(labels), frozenset(expected_labels)) self.assertSetEqual(frozenset(coeffs), frozenset(expected_coeffs))
def test_mapping(self): """ Test mapping to qubit operator """ driver = GaussianForcesDriver(logfile=self.get_resource_path( 'CO2_freq_B3LYP_ccpVDZ.log', 'problems/second_quantization/vibrational/resources')) watson_hamiltonian = driver.run() num_modals = 2 truncation = 3 vibration_op = _build_vibrational_op(watson_hamiltonian, num_modals, truncation) mapper = DirectMapper() qubit_op = mapper.map(vibration_op) self.assertEqual(qubit_op, REFERENCE)