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 node-removal methods linear in node degree #1083

Merged
merged 6 commits into from
Apr 5, 2024

Commits on Feb 8, 2024

  1. Add node-removal methods linear in node degree

    The existing method, `PyDiGraph.remove_node_retain_edges` is quadratic
    in node degree, because the ``condition`` function takes in pairs of
    edges.  This poses a problem for extreme-degree nodes (for example
    massive barriers in Qiskit).
    
    This commit adds two methods based on making edge-retention decisions by
    hashable keys, making it linear in the degree of the node (at least;
    the MIMO broadcasting can make it quadratic again if all edges have the
    same key, but that's fundamental to the output, rather than the
    algorithm).
    
    The ideal situation (for performance) is that the edges can be
    disambiguated by Python object identity, which doesn't require
    Python-space calls to retrieve or hash, so can be in pure Rust.  This is
    `remove_node_retain_edges_by_id`.
    
    The more general situation is that the user wants to supply a Python key
    function, which naturally returns a Python object that we need to use
    Python hashing and equality semantics for.  This means using Python
    collections to do the tracking, which impacts the performance (very
    casual benchmarking using the implicit identity function as the key
    shows it's about 2x slower than using the identity).  This method is
    `remove_node_retain_edges_by_key`.
    jakelishman committed Feb 8, 2024
    Configuration menu
    Copy the full SHA
    a0df600 View commit details
    Browse the repository at this point in the history
  2. Format

    jakelishman committed Feb 8, 2024
    Configuration menu
    Copy the full SHA
    f86e8b7 View commit details
    Browse the repository at this point in the history

Commits on Apr 5, 2024

  1. Configuration menu
    Copy the full SHA
    e49fb56 View commit details
    Browse the repository at this point in the history
  2. Update conversion actions to be by Bound reference

    This is partly a PyO3 0.21 upgrade, partly fixing a dodgy `extract` in
    favour of `downcast`.
    jakelishman committed Apr 5, 2024
    Configuration menu
    Copy the full SHA
    ab20d3c View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    9f3a0a7 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    bdb8164 View commit details
    Browse the repository at this point in the history