def test_batched_contract_between_with_matrices(backend): net = batchtensornetwork.BatchTensorNetwork(backend=backend) a = net.add_node(np.ones([10, 2, 2])) b = net.add_node(np.ones([10, 2, 2])) net.connect(a[2], b[1]) c = net.batched_contract_between(a, b, a[0], b[0]) np.testing.assert_allclose(c.tensor, 2 * np.ones([10, 2, 2]))
def create_network( self, data: tf.Tensor, data0: tf.Tensor ) -> Tuple[batchtensornetwork.BatchTensorNetwork, List[tensornetwork.Node], Tuple[tensornetwork.Node]]: """Creates TensorNetwork with MPS and data. Args: data: Tensor of input data of shape (n_batch, n_sites, d_phys). data0: Tensor of input data at the boundary of shape (n_batch, d_phys). Returns: net: TensorNetwork object containing the nodes. var_nodes: List of the two MPS nodes. data_nodes: Tuple of the two data nodes. """ net = batchtensornetwork.BatchTensorNetwork() # Connect the bond edges of the MPS tensors var_nodes = [net.add_node(self.vector), net.add_node(self.matrices)] net.connect(var_nodes[0][1], var_nodes[1][2]) # Connect the data nodes with the physical edges of the MPS tensors data_nodes = (net.add_node(data0), net.add_node(data)) net.connect(data_nodes[0][1], var_nodes[0][0]) net.connect(data_nodes[1][2], var_nodes[1][1]) return net, var_nodes, data_nodes
def test_batched_contract_between_multiple_shared_edges(backend): net = batchtensornetwork.BatchTensorNetwork(backend=backend) a = net.add_node(np.ones([5, 3, 4, 9])) b = net.add_node(np.ones([9, 4, 5])) net.connect(a[2], b[1]) net.connect(a[3], b[0]) c = net.batched_contract_between(a, b, a[0], b[2]) np.testing.assert_allclose(c.tensor, 36 * np.ones([5, 3]))
def test_pairwise_reduction_multiple_edges(): net = batchtensornetwork.BatchTensorNetwork(backend="tensorflow") a = net.add_node(np.ones([3, 5, 6, 2, 2])) b = batchtensornetwork.pairwise_reduction(net, a, a[1]) np.testing.assert_allclose(b.tensor, 16 * np.ones([3, 6, 2, 2]))
def test_pairwise_reduction(): net = batchtensornetwork.BatchTensorNetwork(backend="tensorflow") a = net.add_node(np.ones([10, 2, 2])) b = batchtensornetwork.pairwise_reduction(net, a, a[0]) np.testing.assert_allclose(b.tensor, 512 * np.ones([2, 2]))