Skip to content

Commit

Permalink
Fix: Assign positions for unordered nodes (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudon authored May 16, 2024
1 parent 3c48f14 commit fa0a2ae
Show file tree
Hide file tree
Showing 14 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8, 3.9]
python-version: ["3.9", "3.10"]

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion netsalt/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging

import numpy as np
from skimage.feature import peak_local_max
from skimage.feature import peak_local_max # pylint: disable=no-name-in-module

from .quantum_graph import mode_quality

Expand Down
4 changes: 2 additions & 2 deletions netsalt/quantum_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,8 @@ def _set_node_positions(graph, positions=None):
positions = nx.spring_layout(graph)
L.warning("No node positions given, plots will have random positions from spring_layout")

for u in graph.nodes():
graph.nodes[u]["position"] = positions[u]
for i, u in enumerate(graph.nodes()):
graph.nodes[u]["position"] = positions[i]


def _set_edge_lengths(graph, lengths=None):
Expand Down
3 changes: 1 addition & 2 deletions netsalt/tasks/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import seaborn as sns
import yaml
from matplotlib.backends.backend_pdf import PdfPages
from matplotlib.cm import get_cmap
from matplotlib.colors import ListedColormap

from netsalt.io import load_graph, load_modes, load_qualities
Expand Down Expand Up @@ -67,7 +66,7 @@ def run(self):
print("mean edge length", np.mean(lengths))
print("total edge length", sum(lengths))

cmap = get_cmap("Pastel1_r")
cmap = plt.get_cmap("Pastel1_r")
newcolors = cmap(np.take(np.linspace(0, 1, 9), [0, 4, 2, 3, 1, 8, 6, 7, 5]))
newcmp = ListedColormap(newcolors)
plot_quantum_graph(
Expand Down
4 changes: 3 additions & 1 deletion netsalt/tasks/pump.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def run(self):
disp=self.disp,
)

if self.optimisation_mode == "linear_programming":
elif self.optimisation_mode == "linear_programming":
optimal_pump, pump_overlapps, costs, final_cost = optimize_pump_linear_programming(
modes_df,
qg,
Expand All @@ -65,6 +65,8 @@ def run(self):
eps_n=self.eps_n,
cost_diff_min=self.cost_diff_min,
)
else:
raise ValueError(f"unknown optimisation mode {self.optimisation_mode}")

results = {
"optimal_pump": optimal_pump,
Expand Down
Binary file modified tests/data/run_simple/out/lasing_thresholds_modes.h5
Binary file not shown.
Binary file modified tests/data/run_simple/out/modal_intensities.h5
Binary file not shown.
Binary file modified tests/data/run_simple/out/mode_competition_matrix.h5
Binary file not shown.
Binary file modified tests/data/run_simple/out/mode_trajectories.h5
Binary file not shown.
Binary file modified tests/data/run_simple/out/passive_modes.h5
Binary file not shown.
Binary file modified tests/data/run_simple/out/qualities.h5
Binary file not shown.
Binary file removed tests/data/run_simple/out/quantum_graph.gpickle
Binary file not shown.
13 changes: 8 additions & 5 deletions tests/test_functional.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Fuctional test of the workflow."""

import shutil
import os
from pathlib import Path
Expand Down Expand Up @@ -38,15 +39,15 @@ def create_graph():
netsalt.save_graph(graph, "graph.pkl")

# create the index of refraction profile
custom_index = len(graph.edges) * [3.0 ** 2]
custom_index = len(graph.edges) * [3.0**2]
custom_loss = len(graph.edges) * [0.0]
custom_index[0] = 1.0 ** 2
custom_index[-1] = 1.0 ** 2
custom_index[0] = 1.0**2
custom_index[-1] = 1.0**2

count_inedges = len(graph.edges) - 2.0
if count_inedges % 4 == 0:
for i in range(round(count_inedges / 4)):
custom_index[i + 1] = 1.5 ** 2
custom_index[i + 1] = 1.5**2

yaml.dump({"constant": custom_index, "loss": custom_loss}, open("index.yaml", "w"))

Expand Down Expand Up @@ -86,4 +87,6 @@ def test_ComputeLasingModes(working_directory):

# Check the numerical results
result_dir, expected_dir = working_directory
assert_equal_trees(expected_dir, result_dir)
assert_equal_trees(
expected_dir, result_dir, specific_args={"out": {"patterns": [r".*\.h5$"], "atol": 1e-5}}
)
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ max-line-length=100

[gh-actions]
python =
3.8: py38, lint
3.9: py39
3.9: py39, lint
3.10: py310

0 comments on commit fa0a2ae

Please sign in to comment.