def test_flattened_tensor_product(): observable_one = Observable.Z() @ Observable.Y() observable_two = Observable.X() @ Observable.H() actual = Observable.TensorProduct([observable_one, observable_two]) expected = Observable.TensorProduct( [Observable.Z(), Observable.Y(), Observable.X(), Observable.H()] ) assert expected == actual
def test_tensor_product_matmul_tensor(): t1 = Observable.TensorProduct([Observable.Z(), Observable.I(), Observable.X()]) t2 = Observable.TensorProduct( [Observable.Hermitian(matrix=Observable.I().to_matrix()), Observable.Y()] ) t3 = t1 @ t2 assert t3.to_ir() == ["z", "i", "x", [[[1.0, 0], [0, 0]], [[0, 0], [1.0, 0]]], "y"] assert t3.qubit_count == 5 assert t3.ascii_symbols == tuple(["Z@I@X@Hermitian@Y"] * 5)
def test_tensor_product_to_ir(): t = Observable.TensorProduct( [Observable.Z(), Observable.I(), Observable.X()]) assert t.to_ir() == ["z", "i", "x"] assert t.qubit_count == 3 assert t.ascii_symbols == tuple(["Z@I@X"] * 3)
def test_tensor_product_rmatmul_observable(): t1 = Observable.TensorProduct([Observable.Z(), Observable.I(), Observable.X()]) o1 = Observable.I() t = o1 @ t1 assert t.to_ir() == ["i", "z", "i", "x"] assert t.qubit_count == 4 assert t.ascii_symbols == tuple(["I@Z@I@X"] * 4)
def test_observable_from_ir_tensor_product(): expected_observable = Observable.TensorProduct( [Observable.Z(), Observable.I(), Observable.X()]) actual_observable = observable_from_ir(["z", "i", "x"]) assert expected_observable == actual_observable
def test_tensor_product_rmatmul_value_error(): "a" @ Observable.TensorProduct( [Observable.Z(), Observable.I(), Observable.X()])
def test_tensor_product_value_error(): Observable.TensorProduct([Observable.Z(), Observable.I(), Observable.X()]) @ "a"
def test_tensor_product_eigenvalue_index_out_of_bounds(): obs = Observable.TensorProduct( [Observable.Z(), Observable.I(), Observable.X()]) obs.eigenvalue(8)