Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _sampling(self, king_graph, var_type, token):
indices = king_graph.indices
response = Response(var_type=var_type, indices=indices)
headers, request = self.make_json_request(king_graph.get_ising_king_graph(), token)
url = 'https://annealing-cloud.com/api/v2/solve'
res = requests.post(url, data=json.dumps(request), headers=headers)
res_dict = res.json()
if res_dict['status'] != 0:
raise ValueError('Error status: {}, message: {}'.format(res_dict['status'], res_dict['message']))
if var_type == "SPIN":
response.states = [[s for x, y, s in spins] for spins in res_dict['result']['spins']]
else: #qubo
response.states = [[int((s+1)/2) for x, y, s in spins] for spins in res_dict['result']['spins']]
response.indices = [king_graph.convert_to_index(x, y) for x, y, s in res_dict['result']['spins'][0]]
response.energies = np.array(res_dict['result']['energies']) + king_graph.energy_bias