Skip to content

Commit

Permalink
fix: when load url from disk, should modify class attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhaoyilunnn committed Aug 24, 2023
1 parent a53cdbe commit 51876f6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/quafu/backends/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def get_chip_info(self, user: User = None):
api_token = user.api_token
data = {"system_name": self.name.lower()}
headers = {"api_token": api_token}
chip_info = requests.post(url=User.chip_api, data=data, headers=headers)
url = User.url + User.chip_api
chip_info = requests.post(url=url, data=data, headers=headers)
chip_info = json.loads(chip_info.text)
json_topo_struct = chip_info["topological_structure"]
qubits_list = []
Expand Down
6 changes: 3 additions & 3 deletions src/quafu/tasks/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,9 @@ def send(
}

if wait:
url = User.exec_api
url = User.url + User.exec_api
else:
url = User.exec_async_api
url = User.url + User.exec_async_api

logging.debug("quantum circuit validated, sending task...")
headers = {
Expand Down Expand Up @@ -279,7 +279,7 @@ def retrieve(self, taskid: str) -> ExecResult:
taskid: The taskid of the task need to be retrieved.
"""
data = {"task_id": taskid}
url = User.exec_recall_api
url = User.url + User.exec_recall_api

headers = {
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
Expand Down
15 changes: 8 additions & 7 deletions src/quafu/users/userapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@

class User(object):
url = "https://quafu.baqis.ac.cn/"
backends_api = url + "qbackend/get_backends/"
chip_api = url + "qbackend/scq_get_chip_info/"
exec_api = url + "qbackend/scq_kit/"
exec_async_api = url + "qbackend/scq_kit_asyc/"
exec_recall_api = url + "qbackend/scq_task_recall/"
backends_api = "qbackend/get_backends/"
chip_api = "qbackend/scq_get_chip_info/"
exec_api = "qbackend/scq_kit/"
exec_async_api = "qbackend/scq_kit_asyc/"
exec_recall_api = "qbackend/scq_task_recall/"

def __init__(self, api_token: str = None, token_dir: str = None):
"""
Expand Down Expand Up @@ -91,15 +91,16 @@ def _load_account_token(self):
with open(file_dir, "r") as f:
items = f.readlines()
token = items[0].strip()
self.url = items[1].strip()
self.__class__.url = items[1].strip()
return token

def _get_backends_info(self):
"""
Get available backends information
"""
headers = {"api_token": self.api_token}
response = requests.post(url=self.backends_api, headers=headers)
url = self.url + self.backends_api
response = requests.post(url=url, headers=headers)
backends_info = response.json()
if response.status_code == 201:
raise UserError(backends_info["message"])
Expand Down

0 comments on commit 51876f6

Please sign in to comment.