Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if skip > 0:
if gate is not None:
raise ValueError(
"Overlapping gates in same layer at site {}!".format(n))
skip -= 1
elif gate is not None:
site_edges, n_gate = _apply_op_network(site_edges, gate, n)
nodes.append(n_gate)
# keep track of how many sites this gate included
op_sites = len(gate.shape) // 2
skip = op_sites - 1
# NOTE: This may not be the optimal order if transpose costs are considered.
n_psi = reduce(tensornetwork.contract_between, nodes)
n_psi.reorder_edges(site_edges)
return n_psi.tensor
for obs_node, obs_wires in zip(obs_nodes, wires):
meas_wires.extend(obs_wires)
for idx, w in enumerate(obs_wires):
output_idx = idx
input_idx = len(obs_wires) + idx
self._add_edge(obs_node, input_idx, ket, w) # A|psi>
self._add_edge(bra, w, obs_node, output_idx) # tolerance:
warnings.warn(
"Nonvanishing imaginary part {} in expectation value.".format(expval.imag),
RuntimeWarning,
)
return self._real(expval)
# [output_idx1, output_idx2, ..., input_idx1, input_idx2, ...]
for obs_node, obs_wires in zip(obs_nodes, wires):
meas_wires.extend(obs_wires)
for idx, w in enumerate(obs_wires):
output_idx = idx
input_idx = len(obs_wires) + idx
self._add_edge(obs_node, input_idx, ket, w) # A|psi>
self._add_edge(bra, w, obs_node, output_idx) # tolerance:
warnings.warn(
"Nonvanishing imaginary part {} in expectation value.".format(expval.imag),
RuntimeWarning,
)
return self._real(expval)
"""
env = env_iso(hamiltonian, state, isometry, disentangler)
nenv = tensornetwork.Node(env, axis_names=["l", "r", "t"], backend="jax")
output_edges = [nenv["l"], nenv["r"], nenv["t"]]
nu, _, nv, _ = tensornetwork.split_node_full_svd(
nenv,
[nenv["l"], nenv["r"]],
[nenv["t"]],
left_edge_name="s1",
right_edge_name="s2")
nu["s1"].disconnect()
nv["s2"].disconnect()
tensornetwork.connect(nu["s1"], nv["s2"])
nres = tensornetwork.contract_between(nu, nv, output_edge_order=output_edges)
return np.conj(nres.get_tensor())