Skip to content

Conversation

kaelynj
Copy link
Collaborator

@kaelynj kaelynj commented Sep 29, 2025

Closes #3523

Notebook fixes were implemented earlier, but the outputs needed to be updated.

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@kaelynj kaelynj requested a review from miamico September 29, 2025 15:24
@qiskit-bot
Copy link
Contributor

One or more of the following people are relevant to this code:

@miamico
Copy link
Collaborator

miamico commented Sep 29, 2025

Cool, the small instance looks correct! Not sure how to verify the large instance though. any ideas? OItherwise good to publish.
Another minor comment, but not a necessary change, is to "prettyfy" the plot of the 100q graph by assignig coordinates to the nodes in the graph. Below an example code where G_edges is a the list of edges in the coupling map (gives the topology of the device) and P_edges is a subgraph of the device:

import networkx as nx
graph_G = nx.Graph()
graph_G.add_edges_from(G_edges)

graph_P = nx.Graph()
graph_P.add_edges_from(P_edges)

# pos = nx.spring_layout(graph_G)
import numpy as np
def _heron_coords_r2():
    """Generate coordinates for the Heron layout in R2. Note"""
    cord_map = np.array(
        [
            [
                0,
                1,
                2,
                3,
                4,
                5,
                6,
                7,
                8,
                9,
                10,
                11,
                12,
                13,
                14,
                15,
                3,
                7,
                11,
                15,
                0,
                1,
                2,
                3,
                4,
                5,
                6,
                7,
                8,
                9,
                10,
                11,
                12,
                13,
                14,
                15,
                1,
                5,
                9,
                13,
                0,
                1,
                2,
                3,
                4,
                5,
                6,
                7,
                8,
                9,
                10,
                11,
                12,
                13,
                14,
                15,
                3,
                7,
                11,
                15,
                0,
                1,
                2,
                3,
                4,
                5,
                6,
                7,
                8,
                9,
                10,
                11,
                12,
                13,
                14,
                15,
                1,
                5,
                9,
                13,
                0,
                1,
                2,
                3,
                4,
                5,
                6,
                7,
                8,
                9,
                10,
                11,
                12,
                13,
                14,
                15,
                3,
                7,
                11,
                15,
                0,
                1,
                2,
                3,
                4,
                5,
                6,
                7,
                8,
                9,
                10,
                11,
                12,
                13,
                14,
                15,
                1,
                5,
                9,
                13,
                0,
                1,
                2,
                3,
                4,
                5,
                6,
                7,
                8,
                9,
                10,
                11,
                12,
                13,
                14,
                15,
                3,
                7,
                11,
                15,
                0,
                1,
                2,
                3,
                4,
                5,
                6,
                7,
                8,
                9,
                10,
                11,
                12,
                13,
                14,
                15,
            ],
            -1
            * np.array([j for i in range(15) for j in [i] * [16, 4][i % 2]]),
        ],
        dtype=int,
    )

    hcords = []
    ycords = cord_map[0]
    xcords = cord_map[1]
    for i in range(156):
        hcords.append([xcords[i] + 1, np.abs(ycords[i]) + 1])

    return hcords

# Get position of nodes for plotting
graph_pos = dict()
coords = _heron_coords_r2()
for i in node_w.keys():
    graph_pos[i] = tuple(coords[i])

# Color nodes chosen
node_colors = []
for node in graph_G.nodes():
    if node in best_map.values():  # Nodes to be colored red
        node_colors.append('red')
    else:  # Other nodes colored blue
        node_colors.append('blue')

nx.draw(graph_G, graph_pos, node_color=node_colors, with_labels=True)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

incorrect result graph in "Quantum approximate optimization algorithm" tutorial

3 participants