Skip to content
New issue

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

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

Already on GitHub? # to your account

Add from complex matrix function #412

Merged
merged 9 commits into from
Sep 10, 2021

Conversation

mtreinish
Copy link
Member

@mtreinish mtreinish commented Aug 16, 2021

This commit adds a new constructor method from_complex_adjacency_matrix
that will build a new graph from an adjacency matrix with complex
elements.

Fixes #411

TODO:

@mtreinish mtreinish added this to the 0.11.0 milestone Aug 16, 2021
Copy link
Collaborator

@IvanIsCoding IvanIsCoding left a comment

Choose a reason for hiding this comment

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

Update: I confirmed it is not possible, we have to stick with the current implementation

I agree that we should make #411 possible, but I would implement this differently.

If we make a generic function that can take arbitrary Python, it would have the same effect and avoid PyO3/pyo3#1798. We could also support optional callables to make it even more flexible e.g:

# without optional arguments
retworkx.PyGraph.from_custom_adjacency_matrix(adjacency_matrix) # complex numbers

# with optional arguments
retworkx.PyGraph.from_custom_adjacency_matrix(
    adjacency_matrix,
    weight_fn=lambda x: x.imag,
    null_value=0.0
) # example to do arbitrary conversions etc

mtreinish and others added 2 commits September 3, 2021 11:40
This commit adds a new constructor method from_complex_adjacency_matrix
that will build a new graph from an adjacency matrix with complex
elements.

Fixes Qiskit#411
This commit updates the implementation of the from_adjacency_matrix()
functions to have a shared generic private function to be shared across
the per type variants. To accomplish this the IsNan trait from rust
nightly is copied into retworkx (so we can build with stable rust). If
in the future if an int type variant is added we'll need to implement
this trait for the int type (and just return false).

Co-authored-by: georgios-ts <45130028+georgios-ts@users.noreply.github.com>
@coveralls
Copy link

coveralls commented Sep 3, 2021

Pull Request Test Coverage Report for Build 1221392238

  • 112 of 112 (100.0%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.01%) to 97.507%

Totals Coverage Status
Change from base Build 1217338001: -0.01%
Covered Lines: 10014
Relevant Lines: 10270

💛 - Coveralls

@mtreinish mtreinish changed the title WIP: Add from complex matrix function Add from complex matrix function Sep 6, 2021
@mtreinish mtreinish removed the on hold label Sep 6, 2021
Co-authored-by: georgios-ts <45130028+georgios-ts@users.noreply.github.com>
@georgios-ts georgios-ts merged commit d257f3d into Qiskit:main Sep 10, 2021
@mtreinish mtreinish deleted the complex-adj-matrix branch September 10, 2021 13:53
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a method to make a graph from a complex matrix
4 participants