Problemas del Modelo de Retícula con v0.5#
Los modelos de retícula solo han recibido algunas actualizaciones menores en esta versión de Qiskit Nature.
Un cambio importante es que, dado que todos los modelos de retícula ahora implementan la nueva interfaz Hamiltonian
en lugar de la anterior Property
, obtienes el operador real a través del método second_q_op()
en lugar de second_q_ops()
(Observa la s
al final).
Descripción General#
En particular, las importaciones han cambiado de la siguiente manera:
Ubicación antigua |
Ubicación nueva |
---|---|
|
|
|
|
|
|
Además, los métodos de fábrica para los objetos Lattice
definidos en las clases LatticeModel
se migraron de la siguiente manera:
Método anterior |
Nuevo método |
---|---|
|
|
|
|
|
|
|
|
Más Recursos#
Asegúrate de consultar los siguientes tutoriales sobre cómo usar el nuevo código:
FermiHubbardModel.uniform_parameters
#
Previamente#
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) * ...
Nuevo#
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
#
Previamente#
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) * ...
Nuevo#
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
#
Previamente#
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)
Nuevo#
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
#
Previamente#
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)
Nuevo#
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 )