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

Add GC support to graph objects #258

Merged
merged 8 commits into from
Mar 2, 2021

Conversation

mtreinish
Copy link
Member

Right now the 2 graph classes in retworkx, PyGraph and PyDiGraph, did
not integrate with the Python garbage collector. This would result in
memory not being cleared in a running python process even if retworkx
objects were only created in temporary context. This commit attempts to
fix this by implementing the garbage collection protocol [1] which
should enable python to clean up retworkx objects when they're no longer
being used.

[1] https://pyo3.rs/v0.12.4/class/protocols.html?highlight=garbage#garbage-collector-integration

Right now the 2 graph classes in retworkx, PyGraph and PyDiGraph, did
not integrate with the Python garbage collector. This would result in
memory not being cleared in a running python process even if retworkx
objects were only created in temporary context. This commit attempts to
fix this by implementing the garbage collection protocol [1] which
should enable python to clean up retworkx objects when they're no longer
being used.

[1] https://pyo3.rs/v0.12.4/class/protocols.html?highlight=garbage#garbage-collector-integration
@mtreinish mtreinish added this to the 0.8.0 milestone Feb 25, 2021
@mtreinish
Copy link
Member Author

I'm marking this on hold because I want to do some performance benchmarks on this before we merge it. But this will be a release blocker because it's causing a memory leak in qiskit-terra.

@coveralls
Copy link

coveralls commented Feb 25, 2021

Pull Request Test Coverage Report for Build 614503023

  • 30 of 30 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.02%) to 96.465%

Totals Coverage Status
Change from base Build 612372672: 0.02%
Covered Lines: 5786
Relevant Lines: 5998

💛 - Coveralls

@mtreinish mtreinish removed the on hold label Feb 25, 2021
@mtreinish
Copy link
Member Author

mtreinish commented Feb 25, 2021

Removing the on hold because I think there really isn't any performance impact here at least from the retworkx side. I ran the transpile benchmark in https://github.com/mtreinish/retworkx-bench and there was no real difference in performance.

@itoko
Copy link
Collaborator

itoko commented Mar 1, 2021

LGTM as a fix for PyGraph and PyDiGraph, but I wonder if we might have other classes that should implement PyGCProtocol trait. What about WeightedEdgeList and BFSSuccessors? (I've grepped "PyObject" and "pub", and found these two.)
==> Oops, sorry. I've just found you added them in #260

@mtreinish
Copy link
Member Author

LGTM as a fix for PyGraph and PyDiGraph, but I wonder if we might have other classes that should implement PyGCProtocol trait. What about WeightedEdgeList and BFSSuccessors? (I've grepped "PyObject" and "pub", and found these two.)
==> Oops, sorry. I've just found you added them in #260

Yep, I did it for the custom return types separately in #260 because I had been wanting __str__ for those return types for some time, so I handled both at the same time there for all 4 of the custom return types and kept it separate from the graph classes.

@mtreinish
Copy link
Member Author

It looks like there is an infrastructure issue with travis CI on ppc64le nodes (the logs just stop without error) I'm going to merge this

@mtreinish mtreinish merged commit cca0993 into Qiskit:master Mar 2, 2021
@mtreinish mtreinish deleted the add-gc-support-to-graph-objects branch March 2, 2021 15:42
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.

5 participants