I'm a beginner with Qiskit and the Python language at all.

Here is my question: One of the VQE function arguments is qubit operator (qubitOp). I saw some examples where the qubitOp object was produced by some already existing Qiskit module.

For example, in the following fragment:

qubitOp, offset = max_cut.get_max_cut_qubitops(w)

qubitOp is an Ising Hamiltonian produced from the connection weights matrix.

But how can I define the qubitOp entirely by myself, from the very beginning? (My actual goal is to enrich the Ising Hamiltonian with spin's interactions with the external magnetic field). Thanks!

  • $\begingroup$ can you include a minimal working example? (here that would be including the imports needed to have that line of code working). A link to the example page you are referring to would also be nice $\endgroup$
    – glS
    Commented Jun 3, 2019 at 10:59
  • $\begingroup$ you can get an idea of how you can define a qubitOp by yourself by having a look at the source code for get_max_cut_qubitops, which you can find here. But a minimal working example would help me get a quick example working more quickly $\endgroup$
    – glS
    Commented Jun 3, 2019 at 11:07

1 Answer 1


The question refers to the VQE, so let's start with this and Max_Cut; they can be built on the VQE. There used to be a vqe.ipynp but I can't find, look for an example.

The VQE algorithm doesn't need much input. You can fill it with the paulis_dict. This could be a simple Z gate for finding the eigenvalues= -1.

pauli_dict = {
    'paulis': [{"coeff": {"imag": 0.0, "real": 1}, "label": "Z"}]

qubitOp = Operator.load_from_dict(pauli_dict)

I will publish my VQE test on github soon. I want to compare Rigetti and IBM VQE.


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.