qiskit-nature
qiskit-nature copied to clipboard
Lattice does not support all rustworkx graph representations.
Environment
- Qiskit Nature version: 0.7.2
- Python version: 3.11
- Operating system: Mac OS ARM
What is happening?
When creating a Lattice from a rustworkx graph Lattice()
only supports graphs of the form
graph = rx.PyGraph(multigraph=False)
graph.extend_from weighted_edge_list(
[(0, 1, 1), (0, 2, 2),
(1, 3, 2), (3, 0, 3)])
rustworkx support two types of weighted graph representations. The above or
graph = rx.PyGraph(multigraph=False)
graph.extend_from weighted_edge_list(
[(0, 1, {'weight': 1}), (0, 2, {'weight': 2}),
(1, 3, {'weight': 2}), (3, 0, {'weight': 3})])
Using the second one results in
ValueError: Unsupported weight {'weight': 1} on edge with index 0.
How can we reproduce the issue?
This should reproduce it with the necessary imports:
graph = rx.PyGraph(multigraph=False)
graph.extend_from_weighted_edge_list(
[(0, 1, {'weight': 1}), (0, 2, {'weight': 2}),
(1, 3, {'weight': 2}), (3, 0, {'weight': 3})])
lattice = Lattice(graph)
What should happen?
A lattice should be constructed given a rustworkx graph in any of the two forms.
Any suggestions?
Either modify lattice.py to take both into account or modify the graph object to be of the correct format.