Skip to content

Commit

Permalink
wip non-abelian transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudon committed Aug 11, 2023
1 parent 52112ef commit c9332b8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
36 changes: 27 additions & 9 deletions netsalt/modes.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,9 @@ def pump_linear(mode_0, graph, D0_0, D0_1):

def mode_on_nodes(mode, graph):
"""Compute the mode solution on the nodes of the graph."""
laplacian = construct_laplacian(to_complex(mode), graph)
laplacian = graph.graph["params"].get("laplacian_constructor", construct_laplacian)(
to_complex(mode), graph
)[0]
min_eigenvalue, node_solution = sc.sparse.linalg.eigs(
laplacian, k=1, sigma=0, v0=np.ones(len(graph)), which="LM"
)
Expand Down Expand Up @@ -901,20 +903,36 @@ def lasing_threshold_linear(mode, graph, D0):

def get_node_transfer(k, graph, input_flow):
"""Compute node transfer from a given input flow."""
BT, _ = construct_incidence_matrix(graph)
laplacian, BT, _, _ = graph.graph["params"].get("laplacian_constructor", construct_laplacian)(
k, graph
)
bt = np.clip(np.ceil(np.real(BT.toarray())), -1, 0)
K = bt.dot(np.repeat(graph.graph["ks"], 2))
return sc.sparse.linalg.spsolve(construct_laplacian(k, graph), K * input_flow)
ks = np.empty(2 * len(graph.graph["ks"]))
ks[::2] = graph.graph["ks"]
ks[1::2] = graph.graph["ks"]
K = bt.dot(ks)
return sc.sparse.linalg.spsolve(laplacian, K * input_flow)


def get_edge_transfer(k, graph, input_flow):
"""Compute edge transfer from a given input flow."""
set_wavenumber(graph, k)
BT, B = construct_incidence_matrix(graph)
_r = sc.sparse.linalg.spsolve(
construct_laplacian(k, graph), BT.dot(np.repeat(graph.graph["ks"], 2) * input_flow)
)
Winv = construct_weight_matrix(graph, with_k=False)
laplacian, BT, B, Winv = graph.graph["params"].get(
"laplacian_constructor", construct_laplacian
)(k, graph)
s = list(np.shape(graph.graph["ks"]))
s[0] *= 2
ks = np.empty(s, dtype=np.complex)
ks[::2] = graph.graph["ks"]
ks[1::2] = graph.graph["ks"]
if len(s) > 1:
_in = np.einsum("ikl,ij", ks, np.diag(input_flow))
_in = BT.dot(sc.linalg.block_diag(*_in))
# WIP HERE
else:
_in = BT.dot(ks * input_flow)

_r = sc.sparse.linalg.spsolve(laplacian, _in)
return Winv.dot(B).dot(_r)


Expand Down
2 changes: 1 addition & 1 deletion netsalt/non_abelian.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,4 @@ def construct_so3_laplacian(wavenumber, graph, abelian_scale=1.0):
set_so3_wavenumber(graph, wavenumber)
BT, B = construct_so3_incidence_matrix(graph, abelian_scale=abelian_scale)
Winv = construct_so3_weight_matrix(graph, abelian_scale=abelian_scale)
return BT.dot(Winv).dot(B)
return BT.dot(Winv).dot(B), BT, B, Winv
4 changes: 2 additions & 2 deletions netsalt/quantum_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def construct_laplacian(wavenumber, graph):
set_wavenumber(graph, wavenumber)
BT, B = construct_incidence_matrix(graph)
Winv = construct_weight_matrix(graph)
return BT.dot(Winv).dot(B)
return BT.dot(Winv).dot(B), BT, B, Winv


def set_wavenumber(graph, wavenumber):
Expand Down Expand Up @@ -447,7 +447,7 @@ def mode_quality(mode, graph, quality_method="eigenvalue"):
graph (graph): quantum graph
quality_method (str): method for quality evaluation (eig, singular value or det)
"""
laplacian = graph.graph["params"].get("laplacian_constructor", construct_laplacian)(
laplacian = graph.graph["params"].get("laplacian_constructor", construct_laplacian)[0](
to_complex(mode), graph
)
return laplacian_quality(laplacian, method=quality_method)

0 comments on commit c9332b8

Please sign in to comment.