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

Implementation of the StableDag data structure #21

Merged
merged 6 commits into from
Sep 14, 2019
Merged

Implementation of the StableDag data structure #21

merged 6 commits into from
Sep 14, 2019

Conversation

davenza
Copy link
Contributor

@davenza davenza commented Sep 6, 2018

This is an early implementation of a StableDag.The code is almost copied from the Dag structure, but using StableGraph instead of Graph. As indicated in the original commit, there are 4 methods that are not implemented because StableGraph does not provide the necessary functions:

raw_nodes() -> Because StableGraph lacks raw_nodes().
node_weights_mut() -> Because StableGraph lacks node_weights_mut().
raw_edges() -> Because StableGraph lacks raw_edges().
edge_weights_mut() -> Because StableGraph lacks edge_weights_mut().

I included the same set of tests for StableDag that is used in the Dag structure in the files
tests/add_edges_stable.rs
tests/iterators_stable.rs
tests/walkers_stable.rs

I also included the tests in tests/stable_indices to test that node/edge indices do not change when we remove an edge/node.

I am pretty new to Rust, so it may need some better code / project organization.

…s based on the StableGraph data structure in petgraph. StableDag contains almost the same functionality as Dag. However, the following methods are not implemented because StableGraph in petgraph does not provide the necessary methods:

raw_nodes() -> Because StableGraph lacks raw_nodes().
node_weights_mut() -> Because StableGraph lacks node_weights_mut().
raw_edges() -> Because StableGraph lacks raw_edges().
edge_weights_mut() -> Because StableGraph lacks edge_weights_mut().
Copy link
Owner

@mitchmindtree mitchmindtree left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much @davenza, this is really great stuff! I've been meaning to get around to this for a while, I can definitely see myself using this down the track.

I just have a couple very minor things to clean up - otherwise I'm more than happy to merge!

So sorry for the delay by the way, it's getting a little overwhelming maintaining what must be ~50 crates by now, whilst also working at my own business! Thanks for being patient with me :)

src/stabledag.rs Outdated Show resolved Hide resolved
src/stabledag.rs Outdated Show resolved Hide resolved
src/stabledag.rs Outdated Show resolved Hide resolved
- Removed commented methods not implemented by petgraph.
- Re-formated the stabledag.rs file to have the same format as lib.rs:
	- In the where clauses, it uses the same space formatting as in lib.rs.
	- Re-formated some comments to fit in 100 columns.
- Corrected typo in the description of the module.
… way to the "stable_graph" feature in petgraph.
@davenza
Copy link
Contributor Author

davenza commented Oct 4, 2018

Hi, thanks for you review. I made the changes you asked for. They are in 5482078.

Then, I added a feature called stable_dag for conditional compilation in cf752f4. What do you think about this?

@davenza
Copy link
Contributor Author

davenza commented Oct 4, 2018

I forgot to include conditional compilation in the tests, but it should be solved in cce14bc.

Copy link
Contributor Author

@davenza davenza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed changes.

@fwcd
Copy link

fwcd commented Sep 13, 2019

Any updates on this PR? I would love to help if there are any specific issues, especially in regard to RustAudio/dsp-chain#103.

@mitchmindtree
Copy link
Owner

Thanks for the reminder @fwcd!

@mitchmindtree mitchmindtree merged commit bcb36c7 into mitchmindtree:master Sep 14, 2019
mtreinish added a commit to Qiskit/rustworkx that referenced this pull request Jan 26, 2020
This commit migrates the internal graph representation of a PyDAG object
from daggy to use stabledigraph in petgraph directly. This removes an
abstraction layer from the stack and also makes it easier to use the dag
in python since the indexes are stable now. The implementation of the
petgraph trait implementations is borrowed heavily from
mitchmindtree/daggy#21 which added a stable
graph dag implementation to daggy. If/when daggy pushes a new release
that includes this implementation and keeps up to date with the latest
version of petgraph it will probably be worth switching back to that
newer version of daggy.

The current issue is most of the petgraph algorithms do not work with
StableGraph types and instead rely solely on Graph types. As a
workaround for this we will need to add local implementations of these
algorithms in the repo. Then after we fix these issues upstream and
include them in a release we can switch back to petgraph's
implementation.

Also, right now the scaling performance of this is limited by the cycle
detection. At sizes above 10,000 nodes it will take more than a second
to add a child, parent, or edge. To avoid this we can either remove the
runtime cycle detection on every add operation. Or alternatively looking
into adapting the rolling cycle detection we were previously getting for
free from daggy.

Fixes #6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants