2
$\begingroup$

There is a Hamiltonian I want to construct by a Python package, which is the following: $$ H = 5.9I + 0.21Z_0 - 6.12 Z_1 - 2.14(X_0X_1 + Y_0Y_1) + 9.6(I-Z_2) - 3.9(X_1X_2 + Y_1Y_2) $$ It is very easy for me to create this Hamiltonian by the Python package Projectq. That is:

h = 5.9*QubitOperator('') + 0.21*QubitOperator('Z0') - 6.12*QubitOperator('Z1') - 2.14*(QubitOperator('X0 X1')+QubitOperator('Y0 Y1') )+ 9.6*(QubitOperator('')-QubitOperator('Z2')) - 3.9*(QubitOperator('X1 X2') + QubitOperator('Y1 Y2') )

However, I want to do this by qiskit. Are there any command like QubitOperator() in qiskit?

$\endgroup$

1 Answer 1

1
$\begingroup$

You can do something like this:

from qiskit.opflow import X, Y, Z, I
H = 5.9*(I^I^I) + 0.21*(Z^I^I) - 6.12*(I^Z^I) - 2.14*(X^X^I) - 2.14*(Y^Y^I) + 9.6*(I^I^I) - 9.6*(I^I^Z) - 3.9*(I^X^X) - 3.9*(I^Y^Y)

You can check your answer by printing out the matrix:

from qiskit.visualization.array import array_to_latex
H_matrix = H.to_matrix()
array_to_latex(H_matrix)

enter image description here

$\endgroup$

Your Answer

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

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