def test_tensor_contract_ident(): qobj = identity([2, 3, 4]) ans = 3 * identity([2, 4]) assert_(ans == tensor_contract(qobj, (1, 4))) # Now try for superoperators. # For now, we just ensure the dims are correct. sqobj = to_super(qobj) correct_dims = [[[2, 4], [2, 4]], [[2, 4], [2, 4]]] assert_equal(correct_dims, tensor_contract(sqobj, (1, 4), (7, 10)).dims)
def case_tensor_contract_other(left, right, pairs, expected_dims, expected_data=None): dat = np.arange(np.product(left) * np.product(right)).reshape((np.product(left), np.product(right))) qobj = Qobj(dat, dims=[left, right]) cqobj = tensor_contract(qobj, *pairs) assert_equal(cqobj.dims, expected_dims) if expected_data is not None: assert_equal(cqobj.data.toarray(), expected_data) else: warnings.warn("tensor_contract test case without checking returned data.")