Comments (3)
rustworkx graph cans actually store arbitrary data as payloads of their nodes and edges.
You cannot possibly cover all possible such payloads and expect the code to extract a weight from it.
That said, the payload which is supported (i.e. just a plain weight) should probably be documented properly. Right now, the only mention of this fact is here:
Therefore, this is either a documentation issue or a feature request to support more types although I would not be sure how this would work in a general case because the Hamiltonian generators which use the lattice would need to be adapted to interpret non-numeric payloads, too.
from qiskit-nature.
This is relevant because networkx graphs only store weights as values in the dictionary and if Lattice()
is given a NetworkX graphs it does the following:
if not isinstance(graph, PyGraph):
_optionals.HAS_NETWORKX.require_now("Lattice construction from networkx.Graph")
graph = networkx_converter(graph)
The network_converter()
will keep the format networkx uses into the rustworkx graph.
I stumbled into this issue trying to take a weighted graph that was built elsewhere with NetworkX into a Lattice(). I had to manually convert it to rustworkx to make sure it wasn’t using a dictionary for the weights before building the lattice.
from qiskit-nature.
Here is an example.
G = nx.Graph()
edges=[[1,2],[0,3],[2,3],[0,1]]
for edge in edges:
edge_1 = edge[0]
edge_2 = edge[1]
weight = 1.0
G.add_edge(edge_1, edge_2,weight=weight)
general_lattice = Lattice(G)
Gives ValueError: Unsupported weight {'weight': 1.0} on edge with index 0.
To fix it we have to manually convert it to an adequately formatted rustworkx object. This works:
G = nx.Graph()
edges=[[1,2],[0,3],[2,3],[0,1]]
for edge in edges:
edge_1 = edge[0]
edge_2 = edge[1]
weight = 1.0
G.add_edge(edge_1, edge_2,weight=weight)
rG = rx.PyGraph(multigraph=G.is_multigraph())
nodes = list(G.nodes)
node_indices = dict(zip(nodes, rG.add_nodes_from(nodes)))
rG.add_edges_from(
[(node_indices[x[0]], node_indices[x[1]], x[2]['weight']) for x in G.edges(data=True)]
)
general_lattice = Lattice(rG)
from qiskit-nature.
Related Issues (20)
- Support V2 Estimator
- Fall 2021-Challenge 2 migrate from 0.2.0 to 0.7.1 HOT 1
- Ci is failing in mypy checks
- parallel_map import from qiskit needs amending
- TextProgressBar is deprecated in Qiskit 0.46 and removed in 1.0
- Add Python 3.12 support
- Update links to qiskit.org/documentation HOT 1
- Speed up fermionic mappers by means of an intermediate conversion to majorana operators HOT 6
- Logarithmic mapper for `BosonicOp` HOT 2
- Night;y CI failing with latest pylint
- ISA circuit support for latest Runtime
- Support complex values in the QCSchema format HOT 2
- PIS4 driver and removing .clean files
- Imcompatible size and shape in `second_q.operators.symmetric_two_body.S8Integrals` Tensor object HOT 1
- What is the point of the register_length() method? HOT 1
- Enable fully occupied spin registers in UCC-like ansatze HOT 1
- Unable to access register_length attribute in FermionicOp class. HOT 1
- PySCF QCSchema is not JSON serializable
- Add a new SAOOVQE solver HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from qiskit-nature.