How to use the tensornetwork.network_components.connect function in tensornetwork

To help you get started, we’ve selected a few tensornetwork examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github google / TensorNetwork / tensornetwork / network_operations.py View on Github external
# instead, which is bad.
  sqrt_s_broadcast_shape = backend.concat(
      [backend.shape(sqrt_s), [1] * (len(vh.shape) - 1)], axis=-1)
  vh_s = vh * backend.reshape(sqrt_s, sqrt_s_broadcast_shape)
  left_node = Node(
      u_s, name=left_name, axis_names=left_axis_names, backend=backend)
  for i, edge in enumerate(left_edges):
    left_node.add_edge(edge, i)
    edge.update_axis(i, node, i, left_node)
  right_node = Node(
      vh_s, name=right_name, axis_names=right_axis_names, backend=backend)
  for i, edge in enumerate(right_edges):
    # i + 1 to account for the new edge.
    right_node.add_edge(edge, i + 1)
    edge.update_axis(i + len(left_edges), node, i + 1, right_node)
  connect(left_node.edges[-1], right_node.edges[0], name=edge_name)
  node.fresh_edges(node.axis_names)
  return left_node, right_node, trun_vals
github google / TensorNetwork / tensornetwork / ncon_interface.py View on Github external
if isinstance(tensor, network_components.BaseNode):
      node = tensor
    else:
      node = network_components.Node(
          tensor, name="tensor_{}".format(i), backend=backend)

    nodes.append(node)

    for (axis_num, edge_lbl) in enumerate(edge_lbls):
      if edge_lbl not in edges:
        e = node[axis_num]
        e.set_name(str(edge_lbl))
        edges[edge_lbl] = e
      else:
        # This will raise an error if the edges are not dangling.
        e = network_components.connect(
            edges[edge_lbl], node[axis_num], name=str(edge_lbl))
        edges[edge_lbl] = e
  return nodes, edges
github google / TensorNetwork / tensornetwork / network_operations.py View on Github external
backend = node.backend
  node.reorder_edges(left_edges + right_edges)
  q, r = backend.qr_decomposition(node.tensor, len(left_edges))
  left_node = Node(
      q, name=left_name, axis_names=left_axis_names, backend=backend)
  for i, edge in enumerate(left_edges):
    left_node.add_edge(edge, i)
    edge.update_axis(i, node, i, left_node)
  right_node = Node(
      r, name=right_name, axis_names=right_axis_names, backend=backend)
  for i, edge in enumerate(right_edges):
    # i + 1 to account for the new edge.
    right_node.add_edge(edge, i + 1)
    edge.update_axis(i + len(left_edges), node, i + 1, right_node)
  connect(left_node.edges[-1], right_node.edges[0], name=edge_name)
  return left_node, right_node
github google / TensorNetwork / tensornetwork / network_operations.py View on Github external
right_axis_names = None
  backend = node.backend
  node.reorder_edges(left_edges + right_edges)
  r, q = backend.rq_decomposition(node.tensor, len(left_edges))
  left_node = Node(
      r, name=left_name, axis_names=left_axis_names, backend=backend)
  for i, edge in enumerate(left_edges):
    left_node.add_edge(edge, i)
    edge.update_axis(i, node, i, left_node)
  right_node = Node(
      q, name=right_name, axis_names=right_axis_names, backend=backend)
  for i, edge in enumerate(right_edges):
    # i + 1 to account for the new edge.
    right_node.add_edge(edge, i + 1)
    edge.update_axis(i + len(left_edges), node, i + 1, right_node)
  connect(left_node.edges[-1], right_node.edges[0], name=edge_name)
  return left_node, right_node
github google / TensorNetwork / tensornetwork / network_operations.py View on Github external
backend.diag(s),
      name=middle_name,
      axis_names=center_axis_names,
      backend=backend)

  right_node = Node(
      vh, name=right_name, axis_names=right_axis_names, backend=backend)

  for i, edge in enumerate(left_edges):
    left_node.add_edge(edge, i)
    edge.update_axis(i, node, i, left_node)
  for i, edge in enumerate(right_edges):
    # i + 1 to account for the new edge.
    right_node.add_edge(edge, i + 1)
    edge.update_axis(i + len(left_edges), node, i + 1, right_node)
  connect(
      left_node.edges[-1], singular_values_node.edges[0], name=left_edge_name)
  connect(
      singular_values_node.edges[1], right_node.edges[0], name=right_edge_name)
  return left_node, singular_values_node, right_node, trun_vals