Skip to content

Commit 2354150

Browse files
Takishimadbretaudbartleyg
authored
ProjectQ v0.5.2 (#385)
* Update on the ibmq client (#379) * Fix install on macOS Big Sur (#383) * Bump version number * Fix tests * Patch travs.yml Co-authored-by: David Bretaud <40793394+dbretaud@users.noreply.github.com> Co-authored-by: Bartley Gillan <bartley.gillan@gmail.com>
1 parent 659304d commit 2354150

File tree

5 files changed

+35
-43
lines changed

5 files changed

+35
-43
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ before_script:
4646
- "echo 'backend: Agg' > matplotlibrc"
4747

4848
# command to run tests
49-
script: export OMP_NUM_THREADS=1 && pytest projectq --cov projectq
49+
script: export OMP_NUM_THREADS=1 && pytest projectq --cov projectq -p no:warnings
5050

5151
after_success:
5252
- coveralls

projectq/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# limitations under the License.
1414

1515
"""Define version number here and read it from setup.py automatically"""
16-
__version__ = "0.5.1"
16+
__version__ = "0.5.2"

projectq/backends/_ibm/_ibm_http_client.py

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def _authenticate(self, token=None):
129129
def _run(self, info, device):
130130
"""
131131
Run the quantum code to the IBMQ machine.
132-
Update since March2020: only protocol available is what they call
132+
Update since September 2020: only protocol available is what they call
133133
'object storage' where a job request via the POST method gets in
134134
return a url link to which send the json data. A final http validates
135135
the data communication.
@@ -162,19 +162,10 @@ def _run(self, info, device):
162162
**json_step1)
163163
request.raise_for_status()
164164
r_json = request.json()
165-
download_endpoint_url = r_json['objectStorageInfo'][
166-
'downloadQObjectUrlEndpoint']
167-
upload_endpoint_url = r_json['objectStorageInfo'][
168-
'uploadQobjectUrlEndpoint']
169165
upload_url = r_json['objectStorageInfo']['uploadUrl']
166+
execution_id = r_json['id']
170167

171-
# STEP2: WE USE THE ENDPOINT TO GET THE UPLOT LINK
172-
json_step2 = {'allow_redirects': True, 'timeout': (5.0, None)}
173-
request = super(IBMQ, self).get(upload_endpoint_url, **json_step2)
174-
request.raise_for_status()
175-
r_json = request.json()
176-
177-
# STEP3: WE USE THE ENDPOINT TO GET THE UPLOT LINK
168+
# STEP2: WE UPLOAD THE CIRCUIT DATA
178169
n_classical_reg = info['nq']
179170
# hack: easier to restrict labels to measured qubits
180171
n_qubits = n_classical_reg # self.backends[device]['nq']
@@ -194,7 +185,7 @@ def _run(self, info, device):
194185
data += ('"parameter_binds": [], "memory_slots": '
195186
+ str(n_classical_reg))
196187
data += (', "n_qubits": ' + str(n_qubits)
197-
+ '}, "schema_version": "1.1.0", ')
188+
+ '}, "schema_version": "1.2.0", ')
198189
data += '"type": "QASM", "experiments": [{"config": '
199190
data += '{"n_qubits": ' + str(n_qubits) + ', '
200191
data += '"memory_slots": ' + str(n_classical_reg) + '}, '
@@ -205,31 +196,31 @@ def _run(self, info, device):
205196
data += '"clbit_labels": ' + str(c_label).replace('\'', '\"') + ', '
206197
data += '"memory_slots": ' + str(n_classical_reg) + ', '
207198
data += '"creg_sizes": [["c", ' + str(n_classical_reg) + ']], '
208-
data += ('"name": "circuit0"}, "instructions": ' + instruction_str
199+
data += ('"name": "circuit0", "global_phase": 0}, "instructions": ' + instruction_str
209200
+ '}]}')
210201

211-
json_step3 = {
202+
json_step2 = {
212203
'data': data,
213204
'params': {
214205
'access_token': None
215206
},
216207
'timeout': (5.0, None)
217208
}
218-
request = super(IBMQ, self).put(r_json['url'], **json_step3)
209+
request = super(IBMQ, self).put(upload_url, **json_step2)
219210
request.raise_for_status()
220211

221-
# STEP4: CONFIRM UPLOAD
222-
json_step4 = {
212+
# STEP3: CONFIRM UPLOAD
213+
json_step3 = {
223214
'data': None,
224215
'json': None,
225216
'timeout': (self.timeout, None)
226217
}
227-
upload_data_url = upload_endpoint_url.replace('jobUploadUrl',
228-
'jobDataUploaded')
229-
request = super(IBMQ, self).post(upload_data_url, **json_step4)
218+
219+
upload_data_url = urljoin(_API_URL,
220+
'Network/ibm-q/Groups/open/Projects/main/Jobs/'+str(execution_id)
221+
+'/jobDataUploaded')
222+
request = super(IBMQ, self).post(upload_data_url, **json_step3)
230223
request.raise_for_status()
231-
r_json = request.json()
232-
execution_id = upload_endpoint_url.split('/')[-2]
233224

234225
return execution_id
235226

projectq/backends/_ibm/_ibm_http_client_test.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def raise_for_status(self):
7777
# Accessing status of device. Return online.
7878
status_url = 'Network/ibm-q/Groups/open/Projects/main/devices/v/1'
7979
if (args[1] == urljoin(_API_URL, status_url)
80-
and (request_num[0] == 1 or request_num[0] == 7)):
80+
and (request_num[0] == 1 or request_num[0] == 6)):
8181
request_num[0] += 1
8282
connections = set([(0, 1), (1, 0), (1, 2), (1, 3), (1, 4), (2, 1),
8383
(2, 3), (2, 4), (3, 1), (3, 4), (4, 3)])
@@ -97,15 +97,15 @@ def raise_for_status(self):
9797
_API_URL,
9898
"Network/ibm-q/Groups/open/Projects/main/Jobs/{execution_id}".
9999
format(execution_id=execution_id)) and not result_ready[0]
100-
and request_num[0] == 6):
100+
and request_num[0] == 5):
101101
result_ready[0] = True
102102
request_num[0] += 1
103103
return MockResponse({"status": "RUNNING"}, 200)
104104
elif (args[1] == urljoin(
105105
_API_URL,
106106
"Network/ibm-q/Groups/open/Projects/main/Jobs/{execution_id}".
107107
format(execution_id=execution_id)) and result_ready[0]
108-
and request_num[0] == 8):
108+
and request_num[0] == 7):
109109
request_num[0] += 1
110110
return MockResponse(
111111
{"status": "COMPLETED"}, 200)
@@ -114,13 +114,13 @@ def raise_for_status(self):
114114
_API_URL,
115115
"Network/ibm-q/Groups/open/Projects/main/Jobs/{execution_id}/resultDownloadUrl".
116116
format(execution_id=execution_id))
117-
and request_num[0] == 9):
117+
and request_num[0] == 8):
118118
request_num[0] += 1
119119
return MockResponse(
120120
{"url": "result_download_url"}, 200)
121121
#STEP7
122122
elif (args[1] == "result_download_url"
123-
and request_num[0] == 10):
123+
and request_num[0] == 9):
124124
request_num[0] += 1
125125
return MockResponse(
126126
{"results": [result]}, 200)
@@ -156,13 +156,14 @@ def raise_for_status(self):
156156
answer1={'objectStorageInfo':{
157157
'downloadQObjectUrlEndpoint':'url_dld_endpoint',
158158
'uploadQobjectUrlEndpoint':'/'+execution_id+'/jobUploadUrl',
159-
'uploadUrl':'url_upld'}
159+
'uploadUrl':'url_upld'},
160+
'id': execution_id
160161
}
161162
return MockPostResponse(answer1,200)
162163

163164
# STEP4
164-
elif (args[1] == "/"+execution_id+"/jobDataUploaded"
165-
and request_num[0] == 5):
165+
elif (args[1] == urljoin(_API_URL, jobs_url + "/"+execution_id+"/jobDataUploaded")
166+
and request_num[0] == 4):
166167
request_num[0] += 1
167168
return MockPostResponse({}, 200)
168169

@@ -171,7 +172,7 @@ def raise_for_status(self):
171172
_API_URL,
172173
"Network/ibm-q/Groups/open/Projects/main/Jobs/{execution_id}/resultDownloaded".
173174
format(execution_id=execution_id))
174-
and request_num[0] == 11):
175+
and request_num[0] == 10):
175176
request_num[0] += 1
176177
return MockPostResponse(
177178
{}, 200)
@@ -195,8 +196,8 @@ def raise_for_status(self):
195196
pass
196197

197198
# STEP3
198-
if (args[1] == "s3_url"
199-
and request_num[0] == 4):
199+
if (args[1] == "url_upld"
200+
and request_num[0] == 3):
200201
request_num[0] += 1
201202
return MockResponse({}, 200)
202203

@@ -579,12 +580,13 @@ def raise_for_status(self):
579580
answer1={'objectStorageInfo':{
580581
'downloadQObjectUrlEndpoint':'url_dld_endpoint',
581582
'uploadQobjectUrlEndpoint':'/'+execution_id+'/jobUploadUrl',
582-
'uploadUrl':'url_upld'}
583+
'uploadUrl':'url_upld'},
584+
'id': execution_id,
583585
}
584586
return MockPostResponse(answer1,200)
585587

586588
# STEP4
587-
elif (args[1] == "/"+execution_id+"/jobDataUploaded"):
589+
elif (args[1] == urljoin(_API_URL, jobs_url + "/"+execution_id+"/jobDataUploaded")):
588590
return MockPostResponse({}, 200)
589591

590592
def mocked_requests_put(*args, **kwargs):
@@ -606,7 +608,7 @@ def raise_for_status(self):
606608
pass
607609

608610
# STEP3
609-
if (args[1] == "s3_url"):
611+
if (args[1] == "url_upld"):
610612
return MockResponse({}, 200)
611613

612614
monkeypatch.setattr("requests.sessions.Session.get", mocked_requests_get)

setup.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,10 +370,9 @@ def _configure_cxx_standard(self):
370370
cxx_standards = [year for year in cxx_standards if year < 17]
371371

372372
if sys.platform == 'darwin':
373-
_, minor_version, _ = [
374-
int(i) for i in platform.mac_ver()[0].split('.')
375-
]
376-
if minor_version < 14:
373+
major_version = int(platform.mac_ver()[0].split('.')[0])
374+
minor_version = int(platform.mac_ver()[0].split('.')[1])
375+
if major_version <= 10 and minor_version < 14:
377376
cxx_standards = [year for year in cxx_standards if year < 17]
378377

379378
for year in cxx_standards:

0 commit comments

Comments
 (0)