Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
for site in reversed(range(n1 + 1, self.center_position)):
nodes[site][2] ^ nodes[site + 1][0]
conj_nodes[site][2] ^ conj_nodes[site + 1][0]
nodes[site][1] ^ conj_nodes[site][1]
edges = {site: node[0] for site, node in nodes.items()}
conj_edges = {site: node[0] for site, node in conj_nodes.items()}
right_env = contract_between(nodes[self.center_position],
conj_nodes[self.center_position])
if self.center_position - 1 in sites:
right_env.reorder_edges(
[edges[self.center_position], conj_edges[self.center_position]])
right_envs[self.center_position - 1] = right_env
for site in reversed(range(n1 + 1, self.center_position)):
right_env = contract_between(right_env, nodes[site])
right_env = contract_between(right_env, conj_nodes[site])
if site - 1 in sites:
right_env.reorder_edges([edges[site], conj_edges[site]])
right_envs[site - 1] = right_env
return right_envs
`Node`: The node at `site`.
"""
if site >= len(self):
raise IndexError(
'index `site` = {} is out of range for len(mps)= {}'.format(
site, len(self)))
if site < 0:
raise ValueError(
'index `site` has to be larger than 0 (found `site`={}).'.format(
site))
if (site == len(self) - 1) and (self.connector_matrix is not None):
self.nodes[site][2] ^ self.connector_matrix[0]
order = [
self.nodes[site][0], self.nodes[site][1], self.connector_matrix[1]
]
return contract_between(
self.nodes[site],
self.connector_matrix,
name=self.nodes[site].name,
output_edge_order=order)
return self.nodes[site]
for site in reversed(range(n1 + 1, self.center_position + 1)):
nodes[site] = Node(self.nodes[site], backend=self.backend)
conj_nodes[site] = conj(self.nodes[site])
nodes[self.center_position][2] ^ conj_nodes[self.center_position][2]
nodes[self.center_position][1] ^ conj_nodes[self.center_position][1]
for site in reversed(range(n1 + 1, self.center_position)):
nodes[site][2] ^ nodes[site + 1][0]
conj_nodes[site][2] ^ conj_nodes[site + 1][0]
nodes[site][1] ^ conj_nodes[site][1]
edges = {site: node[0] for site, node in nodes.items()}
conj_edges = {site: node[0] for site, node in conj_nodes.items()}
right_env = contract_between(nodes[self.center_position],
conj_nodes[self.center_position])
if self.center_position - 1 in sites:
right_env.reorder_edges(
[edges[self.center_position], conj_edges[self.center_position]])
right_envs[self.center_position - 1] = right_env
for site in reversed(range(n1 + 1, self.center_position)):
right_env = contract_between(right_env, nodes[site])
right_env = contract_between(right_env, conj_nodes[site])
if site - 1 in sites:
right_env.reorder_edges([edges[site], conj_edges[site]])
right_envs[site - 1] = right_env
return right_envs
"the specified ordering!".format(
list(map(str, leftovers)), list(
map(str, adjacent_parallel_edges)),
list(map(str, nodes_to_contract))))
con_edges = [e for e in con_edges if e not in edges_to_contract]
if set(nodes_to_contract) == nodes:
# This contraction produces the final output, so order the edges
# here to avoid transposes in some cases.
contraction_output_order = out_edges
else:
contraction_output_order = None
nodes = nodes - set(nodes_to_contract)
nodes.add(
network_components.contract_between(
*nodes_to_contract,
name="con({},{})".format(*nodes_to_contract),
output_edge_order=contraction_output_order))
# TODO: More efficient ordering of products based on out_edges
res_node = network_components.outer_product_final_nodes(nodes, out_edges)
if all(are_nodes):
return res_node
return res_node.tensor
for site in range(self.center_position + 1, n2):
nodes[site][0] ^ nodes[site - 1][2]
conj_nodes[site][0] ^ conj_nodes[site - 1][2]
nodes[site][1] ^ conj_nodes[site][1]
edges = {site: node[2] for site, node in nodes.items()}
conj_edges = {site: node[2] for site, node in conj_nodes.items()}
left_env = contract_between(nodes[self.center_position],
conj_nodes[self.center_position])
left_env.reorder_edges(
[edges[self.center_position], conj_edges[self.center_position]])
if self.center_position + 1 in sites:
left_envs[self.center_position + 1] = left_env
for site in range(self.center_position + 1, n2):
left_env = contract_between(left_env, nodes[site])
left_env = contract_between(left_env, conj_nodes[site])
if site + 1 in sites:
left_env.reorder_edges([edges[site], conj_edges[site]])
left_envs[site + 1] = left_env
return left_envs
nodes[site][0] ^ nodes[site - 1][2]
conj_nodes[site][0] ^ conj_nodes[site - 1][2]
nodes[site][1] ^ conj_nodes[site][1]
edges = {site: node[2] for site, node in nodes.items()}
conj_edges = {site: node[2] for site, node in conj_nodes.items()}
left_env = contract_between(nodes[self.center_position],
conj_nodes[self.center_position])
left_env.reorder_edges(
[edges[self.center_position], conj_edges[self.center_position]])
if self.center_position + 1 in sites:
left_envs[self.center_position + 1] = left_env
for site in range(self.center_position + 1, n2):
left_env = contract_between(left_env, nodes[site])
left_env = contract_between(left_env, conj_nodes[site])
if site + 1 in sites:
left_env.reorder_edges([edges[site], conj_edges[site]])
left_envs[site + 1] = left_env
return left_envs
for edge in edges:
if not edge.is_disabled: #if its disabled we already contracted it
if edge.is_trace():
nodes_set.remove(edge.node1)
nodes_set.add(contract_parallel(edge))
if len(nodes_set) == 1:
# There's nothing to contract.
if ignore_edge_order:
return list(nodes_set)[0]
return list(nodes_set)[0].reorder_edges(output_edge_order)
# Then apply `opt_einsum`'s algorithm
path, nodes = utils.get_path(nodes_set, algorithm)
for a, b in path:
new_node = contract_between(nodes[a], nodes[b], allow_outer_product=True)
nodes.append(new_node)
nodes = utils.multi_remove(nodes, [a, b])
# if the final node has more than one edge,
# output_edge_order has to be specified
final_node = nodes[0] # nodes were connected, we checked this
if not ignore_edge_order:
final_node.reorder_edges(output_edge_order)
return final_node
Args:
gate: a one-body gate
site: the site where the gate should be applied
"""
if len(gate.shape) != 2:
raise ValueError('rank of gate is {} but has to be 2'.format(
len(gate.shape)))
if site < 0 or site >= len(self):
raise ValueError('site = {} is not between 0 <= site < N={}'.format(
site, len(self)))
gate_node = Node(gate, backend=self.backend)
gate_node[1] ^ self.nodes[site][1]
edge_order = [self.nodes[site][0], gate_node[0], self.nodes[site][2]]
self.nodes[site] = contract_between(
gate_node, self.nodes[site],
name=self.nodes[site].name).reorder_edges(edge_order)