Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace NetworkX by RetworkX #1791

Merged
merged 32 commits into from
Dec 22, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
264cb7a
Add retworkx as pl-requirements
maliasadi Oct 15, 2021
305be9c
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane int…
maliasadi Oct 18, 2021
5c33c3e
Add RX support to qaoa/cycle.py
maliasadi Oct 18, 2021
17d0edb
Update RX in qaoa/cycle.py
maliasadi Oct 19, 2021
91b1ed6
Add RX support to qaoa/cost.py
maliasadi Oct 19, 2021
ff8a2d6
Update RX in qaoa/cost.py
maliasadi Oct 19, 2021
310b860
Add RX support to qaoa/mixers.py
maliasadi Oct 19, 2021
298f24f
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane int…
maliasadi Oct 19, 2021
5c50590
Update RX support in qaoa
maliasadi Oct 19, 2021
afabefd
Add RX support to CircuitGraph and update QAOA tests
maliasadi Oct 21, 2021
8529194
Update CircuitGraph
maliasadi Oct 21, 2021
5e03a59
Update RX in circuit_graph
maliasadi Oct 21, 2021
d0cf841
Update CircuitGraph tests
maliasadi Oct 22, 2021
8c70589
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane int…
maliasadi Oct 22, 2021
3a2fe89
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane int…
maliasadi Oct 22, 2021
4d5c10b
Fix merge master conflicts
maliasadi Dec 16, 2021
cb01927
Update RX @ qaoa
maliasadi Dec 17, 2021
c15fbc6
Update formatting
maliasadi Dec 17, 2021
dbc6011
Update circuit_graph
maliasadi Dec 17, 2021
c84d711
Merge branch 'master' of github.com:PennyLaneAI/pennylane into add_re…
maliasadi Dec 17, 2021
85c4680
Add RX support to CircuitGraph
maliasadi Dec 17, 2021
a05f8e9
Merge branch 'master' into add_retworkx_support
maliasadi Dec 17, 2021
e6736f8
Update formatting
maliasadi Dec 17, 2021
4644238
Merge branch 'master' into add_retworkx_support
maliasadi Dec 19, 2021
9a8dcbf
Merge branch 'master' of github.com:PennyLaneAI/pennylane into add_re…
maliasadi Dec 19, 2021
565f449
Merge branch 'add_retworkx_support' of github.com:PennyLaneAI/pennyla…
maliasadi Dec 19, 2021
ccac319
Apply codecov suggestions
maliasadi Dec 20, 2021
7279a2a
Add lollipop_graph_rx
maliasadi Dec 20, 2021
ea31100
Apply code review suggestions
maliasadi Dec 20, 2021
9203c37
Update doc/releases/changelog-dev.md
maliasadi Dec 21, 2021
048cf79
Add more comments
maliasadi Dec 21, 2021
af47884
Update has_path
maliasadi Dec 21, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,12 @@
* Interferometer is now a class with `shape` method.
[(#1946)](https://github.com/PennyLaneAI/pennylane/pull/1946)

* Replace NetworkX by RetworkX in CircuitGraph and add RetworkX support to QAOA.
* The `CircuitGraph`, used to represent circuits via directed acyclic graphs, now
uses RetworkX for its internal representation. This results in significant speedup
for algorithms that rely on a directed acyclic graph representation.
[(#1791)](https://github.com/PennyLaneAI/pennylane/pull/1791)

* The QAOA module now accepts both NetworkX and RetworkX graphs as function inputs.
[(#1791)](https://github.com/PennyLaneAI/pennylane/pull/1791)

<h3>Breaking changes</h3>
Expand Down
17 changes: 14 additions & 3 deletions pennylane/circuit_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ def __init__(self, ops, obs, wires, par_info=None, trainable_params=None):
# This operator does not depend on any others

# Check if wire[0] in self._grid.values()
# is already added to the graph
# is already added to the graph; this
# condition avoids adding new nodes with
# the same value but different indexes
if wire[0] not in self._graph.nodes():
self._graph.add_node(wire[0])

Expand All @@ -189,6 +191,8 @@ def __init__(self, ops, obs, wires, par_info=None, trainable_params=None):
self._graph.add_node(wire[i])

# Create an edge between this and the previous operator
# There isn't any default value for the edge-data in
# rx.PyDiGraph.add_edge(); this is set to an empty string
self._graph.add_edge(
self._graph.nodes().index(wire[i - 1]), self._graph.nodes().index(wire[i]), ""
maliasadi marked this conversation as resolved.
Show resolved Hide resolved
)
Expand Down Expand Up @@ -336,6 +340,7 @@ def ancestors(self, ops):
anc = set(
self._graph.get_node_data(n)
for n in set().union(
# rx.ancestors() returns node indexes instead of node-values
*(rx.ancestors(self._graph, self._graph.nodes().index(o)) for o in ops)
)
)
Expand All @@ -353,6 +358,7 @@ def descendants(self, ops):
des = set(
self._graph.get_node_data(n)
for n in set().union(
# rx.descendants() returns node indexes instead of node-values
*(rx.descendants(self._graph, self._graph.nodes().index(o)) for o in ops)
)
)
Expand Down Expand Up @@ -676,8 +682,13 @@ def has_path(self, a, b):

return (
len(
rx._digraph_dijkstra_shortest_path(
self._graph, self._graph.nodes().index(a), self._graph.nodes().index(b)
rx.digraph_dijkstra_shortest_paths(
maliasadi marked this conversation as resolved.
Show resolved Hide resolved
self._graph,
self._graph.nodes().index(a),
self._graph.nodes().index(b),
weight_fn=None,
default_weight=1.0,
as_undirected=False,
)
)
!= 0
Expand Down