Skip to content

Commit

Permalink
passed test except hubo case
Browse files Browse the repository at this point in the history
  • Loading branch information
j-i-k-o committed May 15, 2021
1 parent 34fa3e9 commit b1ce296
Show file tree
Hide file tree
Showing 23 changed files with 127 additions and 1,531 deletions.
2 changes: 1 addition & 1 deletion benchmark/benchmark2.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
NUM_CALL_UPDATER = 1000


bqm = oj.BinaryQuadraticModel(h, J, var_type='SPIN')
bqm = oj.BinaryQuadraticModel(h, J, vartype='SPIN')

graph = bqm.get_cxxjij_ising_graph(sparse=False)

Expand Down
14 changes: 7 additions & 7 deletions examples/python/example_sa.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class SASampler(BaseSampler):
energy_bias (float):
Energy bias.
var_type (str):
vartype (str):
Type of variables: 'SPIN' or 'BINARY' which mean {-1, 1} or {0, 1}.
indices (int):
Expand Down Expand Up @@ -144,8 +144,8 @@ def sample_ising(self, h, J,
"""

var_type = openjij.SPIN
model = openjij.BinaryQuadraticModel(h=h, J=J, var_type=var_type)
vartype = openjij.SPIN
model = openjij.BinaryQuadraticModel(h=h, J=J, vartype=vartype)
return self.sampling(model,
initial_state=initial_state, updater=updater,
reinitilize_state=reinitilize_state,
Expand Down Expand Up @@ -194,8 +194,8 @@ def sample_qubo(self, Q,
"""

var_type = openjij.BINARY
model = openjij.BinaryQuadraticModel(Q=Q, var_type=var_type)
vartype = openjij.BINARY
model = openjij.BinaryQuadraticModel(Q=Q, vartype=vartype)
return self.sampling(model,
initial_state=initial_state, updater=updater,
reinitilize_state=reinitilize_state,
Expand All @@ -218,7 +218,7 @@ def sampling(self, model,

def _generate_init_state(): return ising_graph.gen_spin()
else:
if model.var_type == openjij.SPIN:
if model.vartype == openjij.SPIN:
_init_state = np.array(initial_state)
else: # BINARY
_init_state = (2*np.array(initial_state)-1).astype(np.int)
Expand Down Expand Up @@ -276,7 +276,7 @@ def exec_sampling():
need_to_convert_from_spin=True))
sampling_time = exec_sampling()
response = openjij.Response(
var_type=model.var_type, indices=self.indices)
vartype=model.vartype, indices=self.indices)
response.update_ising_states_energies(states, energies)

response.info['sampling_time'] = sampling_time * \
Expand Down
16 changes: 8 additions & 8 deletions examples/python/optimizaiton.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class SQASampler(BaseSampler):
energy_bias (float):
Energy bias.
var_type (str):
vartype (str):
Type of variables: 'SPIN' or 'BINARY' which mean {-1, 1} or {0, 1}.
indices (int):
Expand Down Expand Up @@ -147,8 +147,8 @@ def sample_ising(self, h, J,
"""

var_type = openjij.SPIN
bqm = openjij.BinaryQuadraticModel(h=h, J=J, var_type=var_type)
vartype = openjij.SPIN
bqm = openjij.BinaryQuadraticModel(h=h, J=J, vartype=vartype)
return self.sampling(bqm,
initial_state=initial_state, updater=updater,
reinitilize_state=reinitilize_state,
Expand Down Expand Up @@ -185,8 +185,8 @@ def sample_qubo(self, Q,
"""

var_type = openjij.BINARY
bqm = openjij.BinaryQuadraticModel(Q=Q, var_type=var_type)
vartype = openjij.BINARY
bqm = openjij.BinaryQuadraticModel(Q=Q, vartype=vartype)
return self.sampling(bqm,
initial_state=initial_state, updater=updater,
reinitilize_state=reinitilize_state,
Expand All @@ -210,7 +210,7 @@ def sampling(self, model,
def _generate_init_state(): return [ising_graph.gen_spin()
for _ in range(self.trotter)]
else:
if model.var_type == openjij.SPIN:
if model.vartype == openjij.SPIN:
trotter_init_state = [np.array(initial_state)
for _ in range(self.trotter)]
else: # BINARY
Expand Down Expand Up @@ -268,7 +268,7 @@ def exec_sampling():

sampling_time = exec_sampling()
response = openjij.Response(
var_type=model.var_type, indices=self.indices)
vartype=model.vartype, indices=self.indices)
response.update_trotter_ising_states_energies(q_states, q_energies)

response.info['sampling_time'] = sampling_time * \
Expand Down Expand Up @@ -302,7 +302,7 @@ def reverse_annealing():
sqa = oj.SASampler(schedule=reverse_schedule, iteration=20)
res = sqa.sample_qubo(qubo, initial_state=initial_state)
print(res.min_samples)
model = oj.BinaryQuadraticModel(Q=qubo, var_type='BINARY')
model = oj.BinaryQuadraticModel(Q=qubo, vartype='BINARY')
print(model.calc_energy(res.min_samples['min_states'][0]))

print('RQA')
Expand Down
5 changes: 2 additions & 3 deletions openjij/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

from .__version import __version__
from .variable_type import SPIN, BINARY, Vartype, cast_var_type
from .variable_type import SPIN, BINARY, Vartype, cast_vartype
from .sampler import Response
from .sampler import SASampler, SQASampler, CSQASampler
from .sampler import GPUChimeraSQASampler, GPUChimeraSASampler, CMOSAnnealer
from .model import BinaryQuadraticModel, BinaryPolynomialModel, KingGraph, ChimeraModel
from .model import BinaryQuadraticModel, BinaryPolynomialModel
from .utils import solver_benchmark, convert_response
2 changes: 0 additions & 2 deletions openjij/model/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
from .model import *
from .king_graph import *
from .chimera_model import *
Loading

0 comments on commit b1ce296

Please sign in to comment.