Example #1
0
def test_zncharge_dual_invariant(n):
    D = 100
    np.random.seed(10)
    charges = np.random.randint(0, n, D).astype(np.int16)
    a = ZNCharge(n)(charges)
    b = a.dual(True)
    np.testing.assert_allclose((b.charges + a.charges) % n, np.zeros((D, 1)))
Example #2
0
def test_zncharge_raises():
    with pytest.raises(ValueError, match="n must be >= 2, found 0"):
        ZNCharge(0)
    with pytest.raises(ValueError, match="Z7 charges must be in"):
        ZNCharge(7)([0, 4, 9])
    with pytest.raises(ValueError, match="maxval"):
        ZNCharge(3).random(10, 0, 3)
    with pytest.raises(ValueError, match="minval"):
        ZNCharge(3).random(10, -1, 2)
Example #3
0
def test_zncharge_fusion(n):
    D = 100
    np.random.seed(10)
    charges1 = np.random.randint(0, n, D).astype(np.int16)
    charges2 = np.random.randint(0, n, D).astype(np.int16)
    a = ZNCharge(n)(charges1)
    b = ZNCharge(n)(charges2)
    np.testing.assert_allclose(
        np.add.outer(charges1, charges2).ravel() % n, (a + b).charges.ravel())
Example #4
0
def test_Charge_dual_zncharges(n):
    chargetype = ZNCharge(n)
    D = 100
    np.random.seed(10)
    charges = np.random.randint(0, n, D).astype(np.int16)
    q1 = chargetype(charges)
    assert np.all(np.squeeze(q1.dual(True).charges) == (n - charges) % n)
def test_Charge_mul_zncharge(n):
    chargetype = ZNCharge(n)
    D = 100
    np.random.seed(10)
    C1 = np.random.randint(0, n, D).astype(np.int16)
    C2 = np.random.randint(0, n, D).astype(np.int16)
    q1 = chargetype(C1)
    q2 = chargetype(C2)
    q = q1 @ q2
    res = q * True
    np.testing.assert_allclose(res.charges, (n - np.stack([C1, C2])) % n)
Example #6
0
def test_zncharge_does_not_raise():
    ZNCharge(2).random(4)  #pytype: disable=attribute-error
Example #7
0

def test_BaseCharge_unique_sort():
    np.random.seed(10)
    unique_charges = np.array([1, 0, -1])
    labels = np.random.randint(0, 3, 100)
    Q = U1Charge(charges=unique_charges, charge_labels=labels)
    actual = Q.unique(return_index=True,
                      return_inverse=True,
                      return_counts=True)
    np.testing.assert_allclose(actual[0].unique_charges, [[1], [0], [-1]])


@pytest.mark.parametrize('chargetype, B0, B1', [(U1Charge, -5, 5),
                                                (Z2Charge, 0, 1),
                                                (ZNCharge(3), 0, 2),
                                                (ZNCharge(6), 0, 5)])
def test_Charge_charges(chargetype, B0, B1):
    D = 100
    np.random.seed(10)
    charges = np.random.randint(B0, B1 + 1, D).astype(np.int16)
    q1 = chargetype(charges)
    assert np.all(np.squeeze(q1.charges) == charges)


@pytest.mark.parametrize('chargetype, B0, B1,sign', [(U1Charge, -5, 5, -1),
                                                     (Z2Charge, 0, 1, 1)])
def test_Charge_dual(chargetype, B0, B1, sign):
    D = 100
    np.random.seed(10)
    charges = np.random.randint(B0, B1 + 1, D).astype(np.int16)
Example #8
0
def test_zncharge_raises():
    with pytest.raises(ValueError, match="n must be >= 2, found 0"):
        ZNCharge(0)
    with pytest.raises(ValueError, match="Z7 charges must be in"):
        ZNCharge(7)([0, 4, 9])
Example #9
0
def test_zncharge_does_not_raise():
    ZNCharge(2).random(4)