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

QubitPauliString.state_expectation does not work for named qubits #1131

Open
CalMacCQ opened this issue Nov 17, 2023 · 2 comments
Open

QubitPauliString.state_expectation does not work for named qubits #1131

CalMacCQ opened this issue Nov 17, 2023 · 2 comments
Labels
bug Something isn't working stale

Comments

@CalMacCQ
Copy link
Contributor

CalMacCQ commented Nov 17, 2023

I'd expect to be able to calculate $\langle X\rangle$ on a qubit named "p" as follows with QubitPauliString.state_expectation.

from pytket import Circuit, Qubit
from pytket.pauli import Pauli, QubitPauliString

circ = Circuit()
qubit_p = Qubit("p", 0)
circ.add_qubit(qubit_p)

pauli_x = QubitPauliString(circ.qubits, [Pauli.X])
print(pauli_x.state_expectation(circ.get_statevector()))

However this gives

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In[16], line 9
      6 circ.add_qubit(qubit_p)
      8 pauli_x = QubitPauliString(circ.qubits, [Pauli.X])
----> 9 print(pauli_x.state_expectation(circ.get_statevector()))

RuntimeError: Qubit list given to to_sparse_matrix doesn't contain p[0]

If I simply substitute "p" for the default qubit name "q" everything works fine.

@CalMacCQ CalMacCQ added the bug Something isn't working label Nov 17, 2023
@CalMacCQ CalMacCQ changed the title QubitPauliString.state_expectation does not work for named registers QubitPauliString.state_expectation does not work for named qubits Nov 17, 2023
@cqc-alec
Copy link
Collaborator

@willsimmons1465 I'm interested in your opinion on this. It feels like it should work with non-default qubits, but should it? If one digs into the code path there are explicit requirements that the qubit register be the default: e.g. here.

Copy link

github-actions bot commented Jun 8, 2024

This issue has been automatically marked as stale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working stale
Projects
None yet
Development

No branches or pull requests

2 participants