I am looking for a way to implement a projection operator like $\mid +\rangle\langle+\mid$ in qiskits opflow module. I tried Plus @ ~Plus but this gives me an error message. There must be a direct implementation of projection operators right? I can't use the operators in qiskit.quantum_info for what I want to do, except if there is a way to convert those operators to the ones in opflow.

Edit: The error message I get from (Plus)@(~Plus) is ValueError: Composition with a Statefunctions in the first operand is not defined.

The reason I think I can't use qiskit.quantum_info's opearotors it that I want to compute the spectrum using qiskit.algorithms.NumPyEigensolver and this seems to me to not work with a quantum_info operator:

>>>plus = Statevector([1/np.sqrt(2),1/np.sqrt(2)]).to_operator()
Operator([[0.5+0.j, 0.5+0.j],
          [0.5+0.j, 0.5+0.j]],
         input_dims=(2,), output_dims=(2,))

>>>solver = NumPyEigensolver()
>>>spectrum = solver.compute_eigenvalues(plus)
AttributeError: 'Operator' object has no attribute 'to_spmatrix'

I am generally confused about the connection and difference between qiskit.quantum_info and qiskit.opflow because they seem to me to have a large overlap. Is one of those an older module and should not be used anymore? Is there a general way to convert objects like operators from one to the other?

  • $\begingroup$ Welcome to QCSE! There is some context information missing from your question that might help folks answer it: what error message you see and why you think that you can't use operators in qiskit.quantum_info. $\endgroup$ Dec 18 '21 at 0:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.