def extract_indices(self): orbs = range(self.n_orbs) def bit_range_begin(ind): return self.hs.bit_range(ESpaceFermion(ind))[0] return [1 << bit_range_begin(Indices("dn", o)) for o in orbs] + \ [1 << bit_range_begin(Indices("up", o)) for o in orbs]
def test_Indices(self): all_ind = [Indices()] self.assertEqual(len(all_ind[-1]), 0) self.assertEqual(str(all_ind[-1]), "") self.assertEqual([i for i in all_ind[-1]], []) self.assertEqual(all_ind[-1].indices, []) with self.assertRaises(IndexError): all_ind[-1][0] for i in (0, 1, "xxx", "yyy"): all_ind.append(Indices(i)) self.assertEqual(len(all_ind[-1]), 1) self.assertEqual(str(all_ind[-1]), str(i)) self.assertEqual([n for n in all_ind[-1]], [i]) self.assertEqual(all_ind[-1].indices, [i]) self.assertEqual(all_ind[-1].indices[0], i) with self.assertRaises(IndexError): all_ind[-1][1] for i, j in product((0, 1, "xxx", "yyy"), (0, 1, "xxx", "yyy")): all_ind.append(Indices(i, j)) self.assertEqual(len(all_ind[-1]), 2) self.assertEqual(str(all_ind[-1]), "%s,%s" % (i, j)) self.assertEqual([n for n in all_ind[-1]], [i, j]) self.assertEqual(all_ind[-1].indices, [i, j]) self.assertEqual(all_ind[-1].indices[0], i) self.assertEqual(all_ind[-1].indices[1], j) with self.assertRaises(IndexError): all_ind[-1][2] self.check_equality(all_ind) self.check_less_greater(all_ind)
def test_map(self): self.assertEqual(self.hs.dim, 16) def bit_range(ind): return self.hs.bit_range(ESpaceFermion(ind)) self.assertEqual(bit_range(Indices("dn", 1)), (0, 0)) self.assertEqual(bit_range(Indices("dn", 2)), (1, 1)) self.assertEqual(bit_range(Indices("up", 1)), (2, 2)) self.assertEqual(bit_range(Indices("up", 2)), (3, 3)) self.assertEqual(len(self.mapper), 6)
def test_fermion(self): self.assertListEqual(list(map(lambda g: g.indices, self.fermion_ops)), [Indices("dn", 0), Indices("up", 0), Indices("up", 0), Indices("dn", 0)]) for op in self.fermion_ops: self.assertEqual(op.algebra_id, FERMION) for i, op in enumerate(self.fermion_ops): self.assertEqual(op.dagger, (i < 2)) self.check_equality(self.fermion_ops) self.check_less_greater(self.fermion_ops) for op in self.fermion_ops: self.assertIsInstance(op, GeneratorFermion) self.assertNotIsInstance(op, GeneratorBoson) self.assertNotIsInstance(op, GeneratorSpin) self.assertListEqual(list(map(str, self.fermion_ops)), ["C+(dn,0)", "C+(up,0)", "C(up,0)", "C(dn,0)"])
def test_boson(self): self.assertListEqual(list(map(lambda g: g.indices, self.boson_ops)), [Indices("x"), Indices("y"), Indices("y"), Indices("x")]) for op in self.boson_ops: self.assertEqual(op.algebra_id, BOSON) for i, op in enumerate(self.boson_ops): self.assertEqual(op.dagger, (i < 2)) self.check_equality(self.boson_ops) self.check_less_greater(self.boson_ops) for op in self.boson_ops: self.assertNotIsInstance(op, GeneratorFermion) self.assertIsInstance(op, GeneratorBoson) self.assertNotIsInstance(op, GeneratorSpin) self.assertListEqual(list(map(str, self.boson_ops)), ["A+(x)", "A+(y)", "A(y)", "A(x)"])
def test_spin32(self): self.assertListEqual(list(map(lambda g: g.indices, self.spin32_ops)), [Indices(1)] * 3 + [Indices(2)] * 3) for op in self.spin32_ops: self.assertEqual(op.algebra_id, SPIN) self.assertEqual(op.spin, 3 / 2) self.assertEqual(op.multiplicity, 4) self.check_equality(self.spin32_ops) self.check_less_greater(self.spin32_ops) for op in self.spin32_ops: self.assertNotIsInstance(op, GeneratorFermion) self.assertNotIsInstance(op, GeneratorBoson) self.assertIsInstance(op, GeneratorSpin) self.assertListEqual(list(map(str, self.spin32_ops)), ["S3/2+(1)", "S3/2-(1)", "S3/2z(1)", "S3/2+(2)", "S3/2-(2)", "S3/2z(2)"])
def test_init(self): f1 = GeneratorFermion(True, Indices(0, "up")) f2 = GeneratorFermion(True, Indices(0, "up")) f3 = GeneratorFermion(False, Indices(0, "up")) f4 = GeneratorFermion(False, Indices("dn", 0)) self.assertEqual(f1, f2) self.assertNotEqual(f1, f4) self.assertNotEqual(f3, f4) b1 = GeneratorBoson(True, Indices(0, "up")) b2 = GeneratorBoson(True, Indices(0, "up")) b3 = GeneratorBoson(False, Indices(0, "up")) b4 = GeneratorBoson(False, Indices("dn", 0)) self.assertEqual(b1, b2) self.assertNotEqual(b1, b4) self.assertNotEqual(b3, b4) s1 = GeneratorSpin(0.5, SpinComponent.PLUS, Indices("xxx")) s2 = GeneratorSpin(SpinComponent.PLUS, Indices("xxx")) s3 = GeneratorSpin(1.5, SpinComponent.PLUS, Indices("xxx")) s4 = GeneratorSpin(1.5, SpinComponent.MINUS, Indices("xxx")) s5 = GeneratorSpin(1.5, SpinComponent.MINUS, Indices("yyy")) self.assertEqual(s1, s2) self.assertNotEqual(s2, s3) self.assertNotEqual(s3, s4) self.assertNotEqual(s4, s5)