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

SparsePauliOp.apply_layout should do nothing if given None #11026

Closed
nonhermitian opened this issue Oct 16, 2023 · 9 comments · Fixed by #11041
Closed

SparsePauliOp.apply_layout should do nothing if given None #11026

nonhermitian opened this issue Oct 16, 2023 · 9 comments · Fixed by #11041
Assignees
Labels
good first issue Good for newcomers type: feature request New feature or request

Comments

@nonhermitian
Copy link
Contributor

What should we add?

Simulators give None for the layout when a circuit goes through the transpiler. Currently this raises in SparsePauliOp.apply_layout. Rather, it would be nice if None is a null op in apply_layout so that I can run the same code for a sim and a real backend.

@nonhermitian nonhermitian added the type: feature request New feature or request label Oct 16, 2023
@SoranaAurelia
Copy link
Contributor

From my understanding, the only change will be in the apply_layout function by adding the case for a null layout (in which case the function should do nothing). If this is good for a first issue I would like to help with this one :)

@nonhermitian
Copy link
Contributor Author

It is a good first issue, at least in my mind.

@SoranaAurelia
Copy link
Contributor

SoranaAurelia commented Oct 17, 2023

Great! Then I would like to work on it :)

@mtreinish mtreinish added the good first issue Good for newcomers label Oct 18, 2023
@mtreinish
Copy link
Member

I've assigned this issue to you @SoranaAurelia

@rishabhRsinghvi
Copy link

@mtreinish I think it's solved is it?

@jakelishman
Copy link
Member

What behaviour would we expect here if num_qubits is given and is not equal to the number of qubits in the initial operator? My first thought is that that must be an error, but I'm not certain.

@SoranaAurelia
Copy link
Contributor

Maybe we should treat it the same way we treat the case in which the layout is specified and the num_qubits is larger then the num qubits from the layout provided? That is, expanding the operator to the requested number of qubits. Raising an error might also solve the problem, but I think it can be in some cases contradictory to the intention of this feature request: the same code that works for a transpiled circuit for a certain backend might pass while the one transpiled for a simulator will raise due to this. Thanks for catching this!

@nonhermitian
Copy link
Contributor Author

I would also expand the operator.

@jakelishman
Copy link
Member

Personally I'm not a fan of implicitly assuming that the given qubits are the "low" indexed ones - that's the kind of thing a layout is supposed to tell you - but looking at the code, it seems like we've already made that assumption, so it's most consistent to extend it to this case as well. Thanks both.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers type: feature request New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants