Lattice Model Problems with v0.5#
The lattice models have only received some minor updates in this release of Qiskit Nature.
One important change is that since all lattice models now implement
the new Hamiltonian
interface rather than the old Property
one,
you obtain the actual operator via the second_q_op()
method instead
of second_q_ops()
(Note the trailing s
).
Overview#
Most notably, the imports have changed as follows:
Legacy location |
New location |
---|---|
|
|
|
|
|
|
Furthermore, the factory methods for Lattice
objects defined on the
LatticeModel
classes were migrated as follows:
Legacy method |
New method |
---|---|
|
|
|
|
|
|
|
|
Further Resources#
Be sure to check out the following tutorials for how to use the new code:
FermiHubbardModel.uniform_parameters
#
Previously#
from qiskit_nature.problems.second_quantization.lattice.lattices import LineLattice
from qiskit_nature.problems.second_quantization.lattice.models import FermiHubbardModel
line = LineLattice(2)
fermi = FermiHubbardModel.uniform_parameters(line, 2.0, 4.0, 3.0)
print(fermi.second_q_ops()) # Note: the trailing `s`
Fermionic Operator
register length=4, number terms=10
(2+0j) * ( +_0 -_2 )
+ (-2+0j) * ( -_0 +_2 )
+ (4+0j) * ( +_0 -_0 )
+ (4+0j) * ( +_2 -_2 )
+ (2+0j) * ( +_1 -_3 )
+ (-2+0j) * ( -_1 +_3 )
+ (4+0j) * ( +_1 -_1 )
+ (4+0j) * ( +_3 -_3 )
+ (3+0j) * ...
New#
from qiskit_nature.second_q.hamiltonians.lattices import LineLattice
from qiskit_nature.second_q.hamiltonians import FermiHubbardModel
line = LineLattice(2)
fermi = FermiHubbardModel(line.uniform_parameters(2.0, 4.0), 3.0)
print(fermi.second_q_op()) # Note: NO trailing `s`
Fermionic Operator
number spin orbitals=4, number terms=10
2.0 * ( +_0 -_2 )
+ -2.0 * ( -_0 +_2 )
+ 4.0 * ( +_0 -_0 )
+ 4.0 * ( +_2 -_2 )
+ 2.0 * ( +_1 -_3 )
+ -2.0 * ( -_1 +_3 )
+ 4.0 * ( +_1 -_1 )
+ 4.0 * ( +_3 -_3 )
+ 3.0 * ( +_0 -_0 +_1 -_1 )
+ 3.0 * ( +_2 -_2 +_3 -_3 )
FermiHubbardModel.from_parameters
#
Previously#
import numpy as np
from qiskit_nature.problems.second_quantization.lattice.models import FermiHubbardModel
interaction = np.array([[4.0, 2.0], [2.0, 4.0]])
fermi = FermiHubbardModel.from_parameters(interaction, 3.0)
print(fermi.second_q_ops()) # Note: the trailing `s`
Fermionic Operator
register length=4, number terms=10
(4+0j) * ( +_0 -_0 )
+ (2+0j) * ( +_0 -_2 )
+ (-2+0j) * ( -_0 +_2 )
+ (4+0j) * ( +_2 -_2 )
+ (4+0j) * ( +_1 -_1 )
+ (2+0j) * ( +_1 -_3 )
+ (-2+0j) * ( -_1 +_3 )
+ (4+0j) * ( +_3 -_3 )
+ (3+0j) * ...
New#
import numpy as np
from qiskit_nature.second_q.hamiltonians.lattices import Lattice
from qiskit_nature.second_q.hamiltonians import FermiHubbardModel
interaction = np.array([[4.0, 2.0], [2.0, 4.0]])
lattice = Lattice.from_adjacency_matrix(interaction)
fermi = FermiHubbardModel(lattice, 3.0)
print(fermi.second_q_op()) # Note: NO trailing `s`
Fermionic Operator
number spin orbitals=4, number terms=10
4.0 * ( +_0 -_0 )
+ 2.0 * ( +_0 -_2 )
+ -2.0 * ( -_0 +_2 )
+ 4.0 * ( +_2 -_2 )
+ 4.0 * ( +_1 -_1 )
+ 2.0 * ( +_1 -_3 )
+ -2.0 * ( -_1 +_3 )
+ 4.0 * ( +_3 -_3 )
+ 3.0 * ( +_0 -_0 +_1 -_1 )
+ 3.0 * ( +_2 -_2 +_3 -_3 )
IsingModel.uniform_parameters
#
Previously#
from qiskit_nature.problems.second_quantization.lattice.lattices import LineLattice
from qiskit_nature.problems.second_quantization.lattice.models import IsingModel
line = LineLattice(2)
ising = IsingModel.uniform_parameters(line, 2.0, 4.0)
print(ising.second_q_ops()) # Note: the trailing `s`
Z_0 Z_1 * (2+0j)
+ X_0 * (4+0j)
+ X_1 * (4+0j)
New#
from qiskit_nature.second_q.hamiltonians.lattices import LineLattice
from qiskit_nature.second_q.hamiltonians import IsingModel
line = LineLattice(2)
ising = IsingModel(line.uniform_parameters(2.0, 4.0))
print(ising.second_q_op()) # Note: NO trailing `s`
Spin Operator
spin=1/2, number spins=2, number terms=3
2.0 * ( Z_0 Z_1 )
+ 4.0 * ( X_0 )
+ 4.0 * ( X_1 )
IsingModel.from_parameters
#
Previously#
import numpy as np
from qiskit_nature.problems.second_quantization.lattice.models import IsingModel
interaction = np.array([[4.0, 2.0], [2.0, 4.0]])
ising = IsingModel.from_parameters(interaction)
print(ising.second_q_ops()) # Note: the trailing `s`
X_0 * (4+0j)
+ Z_0 Z_1 * (2+0j)
+ X_1 * (4+0j)
New#
import numpy as np
from qiskit_nature.second_q.hamiltonians.lattices import Lattice
from qiskit_nature.second_q.hamiltonians import IsingModel
interaction = np.array([[4.0, 2.0], [2.0, 4.0]])
lattice = Lattice.from_adjacency_matrix(interaction)
ising = IsingModel(lattice)
print(ising.second_q_op()) # Note: NO trailing `s`
Spin Operator
spin=1/2, number spins=2, number terms=3
4.0 * ( X_0 )
+ 2.0 * ( Z_0 Z_1 )
+ 4.0 * ( X_1 )