rustworkx icon indicating copy to clipboard operation
rustworkx copied to clipboard

rx.layers(dag,) return node creation input data, instead of expected index

Open NoromTin opened this issue 3 years ago • 3 comments

What is the expected enhancement?

for working with layers (iterations, etc.), expected nodes indexes, but not data used for creation

it would be nice to have an extension of the functionality, because the reverse index lookup is not efficient

NoromTin avatar Jul 30 '22 11:07 NoromTin

Yeah, I agree having the ability to work with indices would be nice. The layers() function was something we added for qiskit a long time ago and they were using the data payload so I didn't really think about it at the time. Working with indices would definitely be more natural. What do you think adding a parallel function like layer_indices to return a list of NodeIndices objects? Or did you have something else in mind?

mtreinish avatar Aug 05 '22 21:08 mtreinish

In my feel of the solid way "layer_indices" is to harsh. Perhaps this would be a better option: layers(dag, first_layer, isIndexOutput = True) or layers(dag, first_layer, typeOutput = 1) as example

But a separate function is also good)

NoromTin avatar Aug 06 '22 02:08 NoromTin

Ok sure, yeah I think having a kwarg for output type makes sense, the complexity comes from the the rust/python interface layer that likes things to be statically typed so it can generate the conversion code. I'll see what we can come up with, one trick is to convert to a python object in the function directly instead of relying on generated code to convert to a python object. Then we just return a python object and exactly what that is is determined by the function code.

mtreinish avatar Aug 08 '22 12:08 mtreinish