ModelMaker(
n_spins, model_type, name, cost_function_signs=[-1, -1]
)
Utility class for constructing standard Ising energy models used in simulations and experiments.
This class constructs predefined random energy models used for testing
and experimentation. Depending on the chosen model_type, it generates
coupling tensors and initialises an :class:EnergyModel instance.
Source code in src/qemcmc/model/model_maker.py
| def __init__(self, n_spins: int, model_type: str, name: str, cost_function_signs: list = [-1, -1]):
self.name = name
self.n_spins = n_spins
self.cost_function_signs = cost_function_signs or [-1, -1]
if not isinstance(model_type, str):
raise TypeError("model_type must be a string")
if model_type == "Fully Connected Ising":
self.make_fully_connected_ising()
elif model_type == "Fully Connected QUBO":
self.make_fully_connected_binary()
else:
raise ValueError(f"Unknown model_type: {model_type}")
|
make_fully_connected_binary
make_fully_connected_binary()
Transforms the existing Ising couplings into an mathematically
equivalent QUBO model via s = 2x - 1.
Source code in src/qemcmc/model/model_maker.py
| def make_fully_connected_binary(self):
"""
Transforms the existing Ising couplings into an mathematically
equivalent QUBO model via s = 2x - 1.
"""
couplings = self.make_fully_connected_ising(return_couplings=True)
# all_energies_ising = self.model.get_all_energies()
h,J = couplings
#constant = 2*np.sum(J)-np.sum(h)
Q_binary = 4 * J
q_binary = 2 * h - 2 * np.sum(J, axis=1)
binary_couplings = [np.round(q_binary, 4), np.round(Q_binary, 4)]
self.model = EnergyModel(
n=self.n_spins,
couplings=binary_couplings,
name=self.name,
cost_function_signs = [-1,-1],
model_type="binary"
)
|