def test_1031_subs(): t, x, y, z = sp.symbols("t x y z") q_sym = QHStates([QH([t, x, y, x * y * z])]) q_z = q_sym.subs({t: 1, x: 2, y: 3, z: 4}) print("t x y xyz sub 1 2 3 4: ", q_z) assert q_z.equals(QHStates([QH([1, 2, 3, 24])]))
def test_1130_identity(): I2 = QHStates().identity(2, operator=True) print("Operator Idenity, diagonal 2x2", I2) assert I2.qs[0].equals(QH().q_1()) assert I2.qs[1].equals(QH().q_0()) I2 = QHStates().identity(2) print("Idenity on 2 state ket", I2) assert I2.qs[0].equals(QH().q_1()) assert I2.qs[1].equals(QH().q_1())
def test_1305_Lorentz_next_rotation(): with pytest.raises(ValueError): QHStates.Lorentz_next_rotation(qs_1234, q2_states) next_rot: QHStates = QHStates.Lorentz_next_rotation(qs_1234, qs_1324) print("next_rotation: ", next_rot) assert math.isclose(next_rot.qs[0].t, 0) assert math.isclose(next_rot.qs[1].t, 0) assert math.isclose(next_rot.norm_squared().qs[0].t, 2) assert not next_rot.qs[0].equals(next_rot.qs[1])
def test_1305_Lorentz_next_boost(): with pytest.raises(ValueError): QHStates.Lorentz_next_boost(qs_1234, q2_states) next_boost: QHStates = QHStates.Lorentz_next_boost(qs_1234, qs_1324) print("next_boost: ", next_boost) assert next_boost.qs[0].t != 0 assert next_boost.qs[1].t != 0 assert next_boost.norm_squared().qs[0].t != 1 assert not next_boost.qs[0].equals(next_boost.qs[1]) boosted_square = q2_states.rotation_and_or_boost(next_boost).square() q2_states_square = q2_states.square() assert math.isclose(q2_states_square.qs[0].t, boosted_square.qs[0].t)
def test_1140_product(): assert b.product(o).equals( QHStates([QH([10, 0, 0, 0]), QH([20, 0, 0, 0]), QH([30, 0, 0, 0])])) assert b.product(k).equals(QHStates([QH([32, 0, 0, 0])])) assert b.product(o).product(k).equals(QHStates([QH([320, 0, 0, 0])])) assert b.product(b).equals( QHStates([QH([1, 0, 0, 0]), QH([4, 0, 0, 0]), QH([9, 0, 0, 0])])) assert o.product(k).equals( QHStates([QH([40, 0, 0, 0]), QH([50, 0, 0, 0]), QH([60, 0, 0, 0])])) assert o.product(o).equals(QHStates([QH([100, 0, 0, 0])])) assert k.product(k).equals( QHStates([QH([16, 0, 0, 0]), QH([25, 0, 0, 0]), QH([36, 0, 0, 0])])) assert k.product(b).equals( QHStates([ QH([4, 0, 0, 0]), QH([5, 0, 0, 0]), QH([6, 0, 0, 0]), QH([8, 0, 0, 0]), QH([10, 0, 0, 0]), QH([12, 0, 0, 0]), QH([12, 0, 0, 0]), QH([15, 0, 0, 0]), QH([18, 0, 0, 0]), ]))
def test_1304_rotation_and_or_boost(): q1_sq = Q_states.square() beta = 0.003 gamma = 1 / math.sqrt(1 - beta**2) h = QHStates([QH([gamma, gamma * beta, 0, 0])]) q_z = Q_states.rotation_and_or_boost(h) q_z2 = q_z.square() print("q1_sq: ", q1_sq) print("boosted: ", q_z) print("boosted squared: ", q_z2) assert round(q_z2.qs[0].t, 5) == round(q1_sq.qs[0].t, 5)
def test_1038_q_j(): qj = QHStates().q_j(2.0, 3) print("qj(3): ", qj) assert qj.dim == 3 assert qj.qs[0].y == 2.0
def test_1037_q_i(): qi = QHStates().q_i(2.0, 3) print("qi(3): ", qi) assert qi.dim == 3 assert qi.qs[0].x == 2.0
def test_1036_q_1(): q1 = QHStates().q_1(2.0, 3) print("q1(3): ", q1) assert q1.dim == 3 assert q1.qs[0].t == 2.0
def test_1035_q_0(): q0 = QHStates().q_0(3) print("q0(3): ", q0) assert q0.dim == 3
def test_1430_inverse(): q_z = P_states.inverse() print("inverse: ", q_z) assert q_z.equals(QHStates([QH([0, -0.16, 0.12, 0])]))
def test_1302_triple_product(): q_z = Q_states.triple_product(P_states, Q_states) print("triple product: ", q_z) assert q_z.equals(QHStates([QH([-2, 124, -84, 8])]))
def test_1125_trace(): trace = v1123.op(2, 2).trace() print("trace: ", trace) assert trace.equals(QHStates([q_4]))
def test_1312_square(): ns = q_1_q_i.square() ns.print_state("q_1_q_i square") assert ns.equals(QHStates([q_1, q_n1]))
def test_1305_bracket(): bracket1234 = QHStates().bracket(q_1234, QHStates().identity(4, operator=True), q_1234) print("bracket <1234|I|1234>: ", bracket1234) assert bracket1234.equals(QHStates([QH([34, 0, 0, 0])]))
def test_1303_rotate(): q_z = Q_states.rotate(QHStates([q_i])) print("rotate: ", q_z) assert q_z.equals(QHStates([QH([1, -2, 3, 4])]))
def test_1039_q_k(): qk = QHStates().q_k(2.0, 3) print("qk(3): ", qk) assert qk.dim == 3 assert qk.qs[0].z == 2.0
def test_1039_q_random(): qr = QHStates().q_random(-2, 2, dim=3) print("qk(3): ", qr) assert qr.dim == 3 assert qr.qs[0].z != qr.qs[0].t
def test_1230_product_AOpB(): AOpB = A.product(Op).product(B) print("A Op B: ", AOpB) assert AOpB.equals(QHStates([QH([0, 22, 11, 0])]))
def test_1315_norm_squared(): ns = q_1_q_i.norm_squared() ns.print_state("q_1_q_i norm squared") assert ns.equals(QHStates([QH([2, 0, 0, 0])]))
def test_1301_divide_by(): q_z = Q_states.divide_by(Q_states) print("divide_by: ", q_z) assert q_z.equals(QHStates([q_1]))
def test_1150_product_AA(): Aket = deepcopy(A).ket() AA = A.product(Aket) print("<A|A>: ", AA) assert AA.equals(QHStates([QH([17, 0, 0, 0])]))
def test_1318_norm_squared_of_vector(): ns = q_1_q_i.norm_squared_of_vector() ns.print_state("q_1_q_i norm squared of vector") assert ns.equals(QHStates([q_1]))
def test_1290_product_AOp4iB(): AOp4iB = A.product(Op4i).product(B) print("A* Op4i B: ", AOp4iB) assert AOp4iB.equals(QHStates([QH([-9, 24, 0, 8])]))
q_2 = QH([2, 0, 0, 0]) q_n2 = QH([-2, 0, 0, 0]) q_3 = QH([3, 0, 0, 0]) q_n3 = QH([-3, 0, 0, 0]) q_4 = QH([4, 0, 0, 0]) q_5 = QH([5, 0, 0, 0]) q_6 = QH([6, 0, 0, 0]) q_10 = QH([10, 0, 0, 0]) q_n5 = QH([-5, 0, 0, 0]) q_7 = QH([7, 0, 0, 0]) q_8 = QH([8, 0, 0, 0]) q_9 = QH([9, 0, 0, 0]) q_n11 = QH([-11, 0, 0, 0]) q_21 = QH([21, 0, 0, 0]) q_n34 = QH([-34, 0, 0, 0]) v3: QHStates = QHStates([q_3]) v1123: QHStates = QHStates([q_1, q_1, q_2, q_3]) v3n1n21: QHStates = QHStates([q_3, q_n1, q_n2, q_1]) v9: QHStates = QHStates([q_1, q_1, q_2, q_3, q_1, q_1, q_2, q_3, q_2]) v9i: QHStates = QHStates([ QH([0, 1, 0, 0]), QH([0, 2, 0, 0]), QH([0, 3, 0, 0]), QH([0, 4, 0, 0]), QH([0, 5, 0, 0]), QH([0, 6, 0, 0]), QH([0, 7, 0, 0]), QH([0, 8, 0, 0]), QH([0, 9, 0, 0]), ]) vv9 = v9.add(v9i)