def test_get_interaction_operator_below_threshold(self): op = get_interaction_operator(FermionOperator('1^ 1', 0.0)) self.assertEqual(op.constant, 0) self.assertTrue(numpy.allclose(op.one_body_tensor, numpy.zeros( (1, 1)))) self.assertTrue( numpy.allclose(op.two_body_tensor, numpy.zeros((1, 1, 1, 1))))
def test_get_molecular_operator(self): coefficient = 3. operators = ((2, 1), (3, 0), (0, 0), (3, 1)) op = FermionOperator(operators, coefficient) molecular_operator = get_interaction_operator(op) fermion_operator = get_fermion_operator(molecular_operator) fermion_operator = normal_ordered(fermion_operator) self.assertTrue(normal_ordered(op) == fermion_operator) op = FermionOperator('1^ 1') op *= 0.5 * EQ_TOLERANCE molecular_operator = get_interaction_operator(op) self.assertEqual(molecular_operator.constant, 0) self.assertTrue( numpy.allclose(molecular_operator.one_body_tensor, numpy.zeros((2, 2))))
def test_get_molecular_data(self): """Test conversion to MolecularData from InteractionOperator""" coefficient = 3. operators = ((2, 1), (3, 0), (0, 0), (3, 1)) op = FermionOperator(operators, coefficient) molecular_operator = get_interaction_operator(op) molecule = get_molecular_data(molecular_operator, geometry=[['H', [0, 0, 0]]], basis='aug-cc-pvtz', multiplicity=2, n_electrons=1) self.assertTrue(isinstance(molecule, MolecularData)) molecule = get_molecular_data(molecular_operator, geometry=[['H', [0, 0, 0]]], basis='aug-cc-pvtz', multiplicity=2, n_electrons=1, reduce_spin=False) self.assertTrue(isinstance(molecule, MolecularData))
def test_get_interaction_operator_nonmolecular_term(self): with self.assertRaises(InteractionOperatorError): get_interaction_operator(FermionOperator('3^ 2 1'))
def test_get_interaction_operator_bad_2body_term(self): with self.assertRaises(InteractionOperatorError): get_interaction_operator(FermionOperator('3^ 2 1 0'))
def test_get_interaction_operator_too_few_qubits(self): with self.assertRaises(ValueError): get_interaction_operator(FermionOperator('3^ 2^ 1 0'), 3)
def test_get_interaction_operator_bad_input(self): with self.assertRaises(TypeError): get_interaction_operator('3')