2
$\begingroup$

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()
>>>plus
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?

$\endgroup$
1
  • $\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$ Commented Dec 18, 2021 at 0:33

1 Answer 1

1
$\begingroup$

You can convert a qiskit.quantum_info operator to a qiskit.opflow operator easily by passing it as a parameter to PrimitiveOp constructor:

from qiskit.opflow import PrimitiveOp

# |+>
sv = Statevector.from_label('+')

# |+><+|
proj = sv.to_operator()

# Convert to opflow operator:
op = PrimitiveOp(proj)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.