Hamiltonian
oqd_heisenberg_ion.simulators.preprocess.system.hamiltonian
HamiltonianParameters
Base class for Hamiltonian parameters
Source code in src/oqd_heisenberg_ion/simulators/preprocess/system/hamiltonian.py
class HamiltonianParameters:
"""
Base class for Hamiltonian parameters
"""
args = {}
def __init__(self):
"""
initializes member variables
"""
self.hamiltonian_name = None
self.hamiltonian_type = None
self.Delta = None
self.h = None
self.J = None
self.B = None
def update_parameters(self, parameter_dict):
"""
updates the provided dictionary with hamiltonian parameters
Args:
parameter_dict (dict): dict to be updated
Returns:
(dict): updated dict containing the parameter set
"""
parameter_dict["hamiltonian_name"] = self.hamiltonian_name
parameter_dict["hamiltonian_type"] = self.hamiltonian_type
parameter_dict["Delta"] = self.Delta
parameter_dict["h"] = self.h
parameter_dict["J"] = self.J
parameter_dict["B"] = self.B
return parameter_dict
__init__
update_parameters
updates the provided dictionary with hamiltonian parameters
Parameters:
-
parameter_dict(dict) –dict to be updated
Returns:
-
dict–updated dict containing the parameter set
Source code in src/oqd_heisenberg_ion/simulators/preprocess/system/hamiltonian.py
def update_parameters(self, parameter_dict):
"""
updates the provided dictionary with hamiltonian parameters
Args:
parameter_dict (dict): dict to be updated
Returns:
(dict): updated dict containing the parameter set
"""
parameter_dict["hamiltonian_name"] = self.hamiltonian_name
parameter_dict["hamiltonian_type"] = self.hamiltonian_type
parameter_dict["Delta"] = self.Delta
parameter_dict["h"] = self.h
parameter_dict["J"] = self.J
parameter_dict["B"] = self.B
return parameter_dict
HamiltonianFactory
Factory for generating the required instance of the HamiltonianParameters subclass. Carries a registry of HamiltonianParameters subclasses
Raises:
-
Exception–if requested subclass is not found
Source code in src/oqd_heisenberg_ion/simulators/preprocess/system/hamiltonian.py
class HamiltonianFactory:
"""
Factory for generating the required instance of the HamiltonianParameters subclass. Carries a registry of HamiltonianParameters subclasses
Raises:
Exception: if requested subclass is not found
"""
registry = {}
def register(cls, name, subclass):
"""
adds the specified subclass to the registry
Args:
name (str): name to be used for subclass
subclass (Type[HamiltonianParameters]): HamiltonianParameters subclass to be registered
"""
cls.registry[name] = subclass
def extract_args(cls, name, **kwargs):
"""
extracts the arguments associated with a given subclass
Args:
name (str): subclass name (must exist in registry)
**kwargs (dict): key word arguments. Must contain inputs for the specific subclass
Returns:
(dict): contains the subclass arguments as key value pairs
"""
arg_vals = {}
for key, arg_dtype in cls.registry[name].args.items():
arg_vals[key] = arg_dtype(kwargs[key])
return arg_vals
def create(cls, name, **kwargs):
"""
creates an instance of the subclass specified
Args:
name (str): name of requested subclass
Raises:
Exception: if the requested HamiltonianParameters subclass is not found in the registry
Returns:
(HamiltonianParameters): instance of the the requested subclass
"""
if name not in cls.registry:
raise Exception(f"HamiltonianParameters implementation not found for name: {name}")
else:
return cls.registry[name](**kwargs)
register
adds the specified subclass to the registry
Parameters:
-
name(str) –name to be used for subclass
-
subclass(Type[HamiltonianParameters]) –HamiltonianParameters subclass to be registered
Source code in src/oqd_heisenberg_ion/simulators/preprocess/system/hamiltonian.py
extract_args
extracts the arguments associated with a given subclass
Parameters:
-
name(str) –subclass name (must exist in registry)
-
**kwargs(dict, default:{}) –key word arguments. Must contain inputs for the specific subclass
Returns:
-
dict–contains the subclass arguments as key value pairs
Source code in src/oqd_heisenberg_ion/simulators/preprocess/system/hamiltonian.py
def extract_args(cls, name, **kwargs):
"""
extracts the arguments associated with a given subclass
Args:
name (str): subclass name (must exist in registry)
**kwargs (dict): key word arguments. Must contain inputs for the specific subclass
Returns:
(dict): contains the subclass arguments as key value pairs
"""
arg_vals = {}
for key, arg_dtype in cls.registry[name].args.items():
arg_vals[key] = arg_dtype(kwargs[key])
return arg_vals
create
creates an instance of the subclass specified
Parameters:
-
name(str) –name of requested subclass
Raises:
-
Exception–if the requested HamiltonianParameters subclass is not found in the registry
Returns:
-
HamiltonianParameters–instance of the the requested subclass
Source code in src/oqd_heisenberg_ion/simulators/preprocess/system/hamiltonian.py
def create(cls, name, **kwargs):
"""
creates an instance of the subclass specified
Args:
name (str): name of requested subclass
Raises:
Exception: if the requested HamiltonianParameters subclass is not found in the registry
Returns:
(HamiltonianParameters): instance of the the requested subclass
"""
if name not in cls.registry:
raise Exception(f"HamiltonianParameters implementation not found for name: {name}")
else:
return cls.registry[name](**kwargs)
FMHeisenbergAFMZ
Bases: HamiltonianParameters
ferromagnetic XXZ model with Delta = -1
Source code in src/oqd_heisenberg_ion/simulators/preprocess/system/hamiltonian.py
class FMHeisenbergAFMZ(HamiltonianParameters):
"""
ferromagnetic XXZ model with Delta = -1
"""
args = {"J": float}
def __init__(self, J):
"""
sets the corresponding member variables
Args:
J (float): energy scale, must be positive for ferromagnetic interactions
Raises:
Exception: if J <= 0
"""
super().__init__()
self.hamiltonian_name = "fm_heisenberg_afm_Z"
self.hamiltonian_type = -1
self.Delta = -1.0
self.h = 0.0
self.J = J
self.B = 0.0
if self.J <= 0:
raise Exception("J must be positive for ferromagnetic interactions")
__init__
sets the corresponding member variables
Parameters:
-
J(float) –energy scale, must be positive for ferromagnetic interactions
Raises:
-
Exception–if J <= 0
Source code in src/oqd_heisenberg_ion/simulators/preprocess/system/hamiltonian.py
def __init__(self, J):
"""
sets the corresponding member variables
Args:
J (float): energy scale, must be positive for ferromagnetic interactions
Raises:
Exception: if J <= 0
"""
super().__init__()
self.hamiltonian_name = "fm_heisenberg_afm_Z"
self.hamiltonian_type = -1
self.Delta = -1.0
self.h = 0.0
self.J = J
self.B = 0.0
if self.J <= 0:
raise Exception("J must be positive for ferromagnetic interactions")
XY
Bases: HamiltonianParameters
XY model
Source code in src/oqd_heisenberg_ion/simulators/preprocess/system/hamiltonian.py
__init__
sets the corresponding member variables
Parameters:
-
J(float) –energy scale
Source code in src/oqd_heisenberg_ion/simulators/preprocess/system/hamiltonian.py
FMHeisenbergFMZ
Bases: HamiltonianParameters
ferromagnetic Heisenberg model
Raises:
-
Exception–if input energy scale J <= 0
Source code in src/oqd_heisenberg_ion/simulators/preprocess/system/hamiltonian.py
class FMHeisenbergFMZ(HamiltonianParameters):
"""
ferromagnetic Heisenberg model
Raises:
Exception: if input energy scale J <= 0
"""
args = {"J": float}
def __init__(self, J):
"""
sets the corresponding member variables
Args:
J (float): energy scale, must be positive for ferromagnetic interactions
Raises:
Exception: if J <= 0
"""
super().__init__()
self.hamiltonian_name = "fm_heisenberg_fm_Z"
self.hamiltonian_type = 1
self.Delta = 1.0
self.h = 0.0
self.J = J
self.B = 0.0
if self.J <= 0:
raise Exception("J must be positive for ferromagnetic interactions")
__init__
sets the corresponding member variables
Parameters:
-
J(float) –energy scale, must be positive for ferromagnetic interactions
Raises:
-
Exception–if J <= 0
Source code in src/oqd_heisenberg_ion/simulators/preprocess/system/hamiltonian.py
def __init__(self, J):
"""
sets the corresponding member variables
Args:
J (float): energy scale, must be positive for ferromagnetic interactions
Raises:
Exception: if J <= 0
"""
super().__init__()
self.hamiltonian_name = "fm_heisenberg_fm_Z"
self.hamiltonian_type = 1
self.Delta = 1.0
self.h = 0.0
self.J = J
self.B = 0.0
if self.J <= 0:
raise Exception("J must be positive for ferromagnetic interactions")
XXZ
Bases: HamiltonianParameters
XXZ model
Source code in src/oqd_heisenberg_ion/simulators/preprocess/system/hamiltonian.py
class XXZ(HamiltonianParameters):
"""
XXZ model
"""
args = {"Delta": float, "J": float}
def __init__(self, Delta, J):
"""
sets the corresponding member variables
Args:
J (float): energy scale
Delta (float): coefficient of the Z_i Z_j term in the Hamiltonian
"""
super().__init__()
self.hamiltonian_name = "XXZ"
self.Delta = Delta
self.hamiltonian_type = 2
self.h = 0.0
self.J = J
self.B = 0.0
__init__
sets the corresponding member variables
Parameters:
-
J(float) –energy scale
-
Delta(float) –coefficient of the Z_i Z_j term in the Hamiltonian
Source code in src/oqd_heisenberg_ion/simulators/preprocess/system/hamiltonian.py
def __init__(self, Delta, J):
"""
sets the corresponding member variables
Args:
J (float): energy scale
Delta (float): coefficient of the Z_i Z_j term in the Hamiltonian
"""
super().__init__()
self.hamiltonian_name = "XXZ"
self.Delta = Delta
self.hamiltonian_type = 2
self.h = 0.0
self.J = J
self.B = 0.0
XXZh
Bases: HamiltonianParameters
XXZ model with a longitudinal field
Source code in src/oqd_heisenberg_ion/simulators/preprocess/system/hamiltonian.py
class XXZh(HamiltonianParameters):
"""
XXZ model with a longitudinal field
"""
args = {"Delta": float, "h": float, "J": float}
def __init__(self, Delta, h, J):
"""
sets the corresponding member variables
Args:
J (float): energy scale
Delta (float): coefficient of the Z_i Z_j term in the Hamiltonian
h (float): longitudinal field strength, must be positive for QMC
"""
super().__init__()
self.hamiltonian_name = "XXZh"
self.Delta = Delta
self.hamiltonian_type = 3
self.h = h
self.J = J
self.B = 0.0
__init__
sets the corresponding member variables
Parameters:
-
J(float) –energy scale
-
Delta(float) –coefficient of the Z_i Z_j term in the Hamiltonian
-
h(float) –longitudinal field strength, must be positive for QMC
Source code in src/oqd_heisenberg_ion/simulators/preprocess/system/hamiltonian.py
def __init__(self, Delta, h, J):
"""
sets the corresponding member variables
Args:
J (float): energy scale
Delta (float): coefficient of the Z_i Z_j term in the Hamiltonian
h (float): longitudinal field strength, must be positive for QMC
"""
super().__init__()
self.hamiltonian_name = "XXZh"
self.Delta = Delta
self.hamiltonian_type = 3
self.h = h
self.J = J
self.B = 0.0
AFMHeisenbergFMZ
Bases: HamiltonianParameters
anti-ferromagnetic Heisenberg model
Raises:
-
Exception–if input energy scale J >= 0
Source code in src/oqd_heisenberg_ion/simulators/preprocess/system/hamiltonian.py
class AFMHeisenbergFMZ(HamiltonianParameters):
"""
anti-ferromagnetic Heisenberg model
Raises:
Exception: if input energy scale J >= 0
"""
args = {"J": float}
def __init__(self, J):
"""
sets the corresponding member variables
Args:
J (float): energy scale, must be negative for anti-ferromagnetic interactions
Raises:
Exception: if J >= 0
"""
super().__init__()
self.hamiltonian_name = "afm_heisenberg_fm_Z"
self.hamiltonian_type = 4
self.Delta = 1.0
self.h = 0.0
self.J = J
self.B = 0.0
if self.J >= 0:
raise Exception("J must be negative for anti-ferromagnetic interactions")
__init__
sets the corresponding member variables
Parameters:
-
J(float) –energy scale, must be negative for anti-ferromagnetic interactions
Raises:
-
Exception–if J >= 0
Source code in src/oqd_heisenberg_ion/simulators/preprocess/system/hamiltonian.py
def __init__(self, J):
"""
sets the corresponding member variables
Args:
J (float): energy scale, must be negative for anti-ferromagnetic interactions
Raises:
Exception: if J >= 0
"""
super().__init__()
self.hamiltonian_name = "afm_heisenberg_fm_Z"
self.hamiltonian_type = 4
self.Delta = 1.0
self.h = 0.0
self.J = J
self.B = 0.0
if self.J >= 0:
raise Exception("J must be negative for anti-ferromagnetic interactions")
XXZhB
Bases: HamiltonianParameters
XXZ model with a longitudinal field and a transverse field. Only usable with ED
Source code in src/oqd_heisenberg_ion/simulators/preprocess/system/hamiltonian.py
class XXZhB(HamiltonianParameters):
"""
XXZ model with a longitudinal field and a transverse field. Only usable with ED
"""
args = {"Delta": float, "h": float, "B": float, "J": float}
def __init__(self, Delta, h, B, J):
"""
sets the corresponding member variables
Args:
J (float): energy scale
Delta (float): coefficient of the Z_i Z_j term in the Hamiltonian
h (float): longitudinal field strength
B (float): transverse field strength
"""
super().__init__()
self.hamiltonian_name = "XXZh"
self.Delta = Delta
self.hamiltonian_type = 5
self.h = h
self.J = J
self.B = B
__init__
sets the corresponding member variables
Parameters:
-
J(float) –energy scale
-
Delta(float) –coefficient of the Z_i Z_j term in the Hamiltonian
-
h(float) –longitudinal field strength
-
B(float) –transverse field strength
Source code in src/oqd_heisenberg_ion/simulators/preprocess/system/hamiltonian.py
def __init__(self, Delta, h, B, J):
"""
sets the corresponding member variables
Args:
J (float): energy scale
Delta (float): coefficient of the Z_i Z_j term in the Hamiltonian
h (float): longitudinal field strength
B (float): transverse field strength
"""
super().__init__()
self.hamiltonian_name = "XXZh"
self.Delta = Delta
self.hamiltonian_type = 5
self.h = h
self.J = J
self.B = B