Repository: openjij/openjij
Issue: In GPU Chimera Sampler, run CPU

change GPU Sampler constructor. Now GPU algorithm overwrites by CPU SA.

Changed files:
openjij/sampler/chimera_gpu/gpu_sa_sampler.py, openjij/sampler/sa_sampler.py, openjij/sampler/chimera_gpu/base_gpu_chimera.py

diff --git a/openjij/sampler/chimera_gpu/base_gpu_chimera.py b/openjij/sampler/chimera_gpu/base_gpu_chimera.py
index 5e5f232b..f31a27fd 100644
--- a/openjij/sampler/chimera_gpu/base_gpu_chimera.py
+++ b/openjij/sampler/chimera_gpu/base_gpu_chimera.py
@@ -21,6 +21,7 @@ import dimod
 
 class BaseGPUChimeraSampler(dimod.Structured):
 
+
     @property
     def parameters(self):
         param = super().parameters
diff --git a/openjij/sampler/chimera_gpu/gpu_sa_sampler.py b/openjij/sampler/chimera_gpu/gpu_sa_sampler.py
index 1c0cb49c..d8adc3ec 100644
--- a/openjij/sampler/chimera_gpu/gpu_sa_sampler.py
+++ b/openjij/sampler/chimera_gpu/gpu_sa_sampler.py
@@ -86,16 +86,36 @@ class GPUSASampler(SASampler, BaseGPUChimeraSampler):
                  num_reads=1, unit_num_L=None,
                  **kwargs):
 
+        super().__init__(beta_min=beta_min, beta_max=beta_max, 
+                         num_reads=num_reads, num_sweeps=num_sweeps, 
+                         schedule=schedule, **kwargs)
+
         self.unit_num_L = unit_num_L
 
-        self._make_system = cxxjij.system.make_chimera_classical_gpu
+        self._make_system = {
+            'singlespinflip': cxxjij.system.make_chimera_classical_gpu
+        }
         self._algorithm = {
             'singlespinflip': cxxjij.algorithm.Algorithm_GPU_run
         }
 
-        super().__init__(beta_min=beta_min, beta_max=beta_max, 
-                         num_reads=num_reads, num_sweeps=num_sweeps, 
-                         schedule=schedule, **kwargs)
+    def sample_ising(self, h, J, beta_min=None, beta_max=None,
+                     num_sweeps=None, num_reads=1, schedule=None,
+                     initial_state=None, updater='single spin flip',
+                     reinitialize_state=True, seed=None, unit_num_L=None,
+                     **kwargs):
+        
+
+        self.unit_num_L = unit_num_L if unit_num_L else self.unit_num_L
+
+        model = openjij.ChimeraModel(linear=h, quadratic=J, var_type='SPIN', 
+                                   unit_num_L=self.unit_num_L, gpu=True)
+        return self._sampling(model, beta_min, beta_max,
+                              num_sweeps, num_reads, schedule,
+                              initial_state, updater,
+                              reinitialize_state, seed, **kwargs)
+
+        
 
 
     
diff --git a/openjij/sampler/sa_sampler.py b/openjij/sampler/sa_sampler.py
index 84afbb1e..57c343c0 100644
--- a/openjij/sampler/sa_sampler.py
+++ b/openjij/sampler/sa_sampler.py
@@ -102,6 +102,7 @@ class SASampler(BaseSampler):
             'swendsenwang': cxxjij.algorithm.Algorithm_SwendsenWang_run
         }
 
+
     def _convert_validation_schedule(self, schedule):
         if not isinstance(schedule, (list, np.array)):
             raise ValueError("schedule should be list or numpy.array")
@@ -132,16 +133,28 @@ class SASampler(BaseSampler):
                      initial_state=None, updater='single spin flip',
                      reinitialize_state=True, seed=None,
                      **kwargs):
-        self._setting_overwrite(
-            beta_min=beta_min, beta_max=beta_max,
-            num_sweeps=num_sweeps, num_reads=num_reads
-        )
 
         model = openjij.BinaryQuadraticModel(
             linear=h, quadratic=J, var_type='SPIN'
         )
+        return self._sampling(model, beta_min, beta_max,
+                              num_sweeps, num_reads, schedule,
+                              initial_state, updater,
+                              reinitialize_state, seed, **kwargs)
+
+    def _sampling(self, model, beta_min=None, beta_max=None,
+                     num_sweeps=None, num_reads=1, schedule=None,
+                     initial_state=None, updater='single spin flip',
+                     reinitialize_state=True, seed=None,
+                     **kwargs):
         ising_graph = model.get_cxxjij_ising_graph()
 
+        self._setting_overwrite(
+            beta_min=beta_min, beta_max=beta_max,
+            num_sweeps=num_sweeps, num_reads=num_reads
+        )
+
+
         # set annealing schedule -------------------------------
         if schedule or self.schedule:
             self._schedule = self._convert_validation_schedule(
@@ -184,7 +197,6 @@ class SASampler(BaseSampler):
         algorithm = self._algorithm[_updater_name]
         sa_system = self._make_system[_updater_name](_generate_init_state(), ising_graph)
         # ------------------------------------------- choose updater
-
         response = self._cxxjij_sampling(
             model, _generate_init_state,
             algorithm, sa_system,