Skip to content

Commit 4d65ec7

Browse files
author
TravisCI
committed
Auto-merged develop -> beta (No conflicts, CI passed)
2 parents e39c629 + f88f757 commit 4d65ec7

File tree

2 files changed

+57
-36
lines changed

2 files changed

+57
-36
lines changed

packages/pygsti/objects/circuit.py

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def _labels_lines_str(self):
250250
@str.setter
251251
def str(self, value):
252252
""" The Python string representation of this Circuit."""
253-
assert(not self._static),"Cannot edit a read-only circuit!"
253+
assert(not self._static),"Cannot edit a read-only circuit! Set editable=True when calling pygsti.obj.Circuit to create editable circuit."
254254
cparser = _CircuitParser()
255255
chk,chk_labels = cparser.parse(value)
256256

@@ -2258,7 +2258,7 @@ def write_Qcircuit_tex(self, filename): #TODO
22582258
f.write("\end{document}")
22592259
f.close()
22602260

2261-
def convert_to_quil(self, gatename_conversion=None, qubit_conversion=None, readout_conversion=None): #TODO
2261+
def convert_to_quil(self, gatename_conversion=None, qubit_conversion=None, readout_conversion=None, block_between_layers=True, block_idles=True): #TODO
22622262
"""
22632263
Converts this circuit to a quil string.
22642264
@@ -2341,13 +2341,17 @@ def convert_to_quil(self, gatename_conversion=None, qubit_conversion=None, reado
23412341
quil_for_gate = gatename_conversion[gate.name]
23422342

23432343
#If gate.qubits is None, gate is assumed to be single-qubit gate
2344-
#acting in parallel on all qubits.
2344+
#acting in parallel on all qubits. If the gate is a global idle, then
2345+
#Pragma blocks are inserted (for tests like idle tomography) even
2346+
#if block_between_layers==False. Set block_idles=False to disable this as well.
23452347
if gate.qubits is None:
23462348
if quil_for_gate == 'I':
2347-
quil += 'PRAGMA PRESERVE_BLOCK\n'
2349+
if block_idles:
2350+
quil += 'PRAGMA PRESERVE_BLOCK\n'
23482351
for q in gate_qubits:
23492352
quil += quil_for_gate + ' ' + str(qubit_conversion[q]) + '\n'
2350-
quil += 'PRAGMA END_PRESERVE_BLOCK\n'
2353+
if block_idles:
2354+
quil += 'PRAGMA END_PRESERVE_BLOCK\n'
23512355
else:
23522356
for q in gate_qubits:
23532357
quil += quil_for_gate + ' ' + str(qubit_conversion[q]) + '\n'
@@ -2371,9 +2375,14 @@ def convert_to_quil(self, gatename_conversion=None, qubit_conversion=None, reado
23712375
if q not in qubits_used:
23722376
quil += 'I' + ' ' + str(qubit_conversion[q]) +'\n'
23732377

2374-
# Add in a barrier after every circuit layer. Future: Should make this optional at some
2375-
# point and/or to agree with the "barriers" in the circuit (to be added).
2376-
quil += 'PRAGMA PRESERVE_BLOCK\nPRAGMA END_PRESERVE_BLOCK\n'
2378+
# Add in a barrier after every circuit layer if block_between_layers==True.
2379+
# Including pragma blocks are critical for QCVV testing, as circuits should usually
2380+
# experience minimal "behind-the-scenes" compilation (beyond necessary
2381+
# conversion to native instructions)
2382+
# To do: Add "barrier" as native pygsti circuit instruction, and use for indicating
2383+
# where pragma blocks should be.
2384+
if block_between_layers:
2385+
quil += 'PRAGMA PRESERVE_BLOCK\nPRAGMA END_PRESERVE_BLOCK\n'
23772386

23782387
# Add in a measurement at the end.
23792388
if readout_conversion==None:
@@ -2387,7 +2396,7 @@ def convert_to_quil(self, gatename_conversion=None, qubit_conversion=None, reado
23872396

23882397
return quil
23892398

2390-
def convert_to_openqasm(self, gatename_conversion=None, qubit_conversion=None): #TODO
2399+
def convert_to_openqasm(self, gatename_conversion=None, qubit_conversion=None, block_between_layers=True): #TODO
23912400
"""
23922401
Converts this circuit to an openqasm string.
23932402
@@ -2456,13 +2465,20 @@ def convert_to_openqasm(self, gatename_conversion=None, qubit_conversion=None):
24562465

24572466
# Find the openqasm for the gate.
24582467
openqasm_for_gate = gatename_conversion[gate.name]
2459-
for q in gate_qubits:
2460-
openqasm_for_gate += ' q[' + str(qubit_conversion[q])+']'
2461-
if q != gate_qubits[-1]:
2462-
openqasm_for_gate += ', '
2463-
openqasm_for_gate += ';\n'
2468+
2469+
#If gate.qubits is None, gate is assumed to be single-qubit gate
2470+
#acting in parallel on all qubits.
2471+
if gate.qubits is None:
2472+
for q in gate_qubits:
2473+
openqasm += openqasm_for_gate + ' q[' + str(qubit_conversion[q])+'];\n'
2474+
else:
2475+
for q in gate_qubits:
2476+
openqasm_for_gate += ' q[' + str(qubit_conversion[q])+']'
2477+
if q != gate_qubits[-1]:
2478+
openqasm_for_gate += ', '
2479+
openqasm_for_gate += ';\n'
24642480
# Add the openqasm for the gate to the openqasm string.
2465-
openqasm += openqasm_for_gate
2481+
openqasm += openqasm_for_gate
24662482

24672483
# Keeps track of the qubits that have been accounted for, and checks that hadn't been used
24682484
# although that should already be checked in the .get_layer(), which checks for its a valid
@@ -2475,13 +2491,18 @@ def convert_to_openqasm(self, gatename_conversion=None, qubit_conversion=None):
24752491
if q not in qubits_used:
24762492
openqasm += 'id' + ' q[' + str(qubit_conversion[q]) +'];\n'
24772493

2478-
# Add in a barrier after every circuit layer. Future: Should make this optional at some
2479-
# point and/or to agree with the "barriers" in the circuit (to be added).
2480-
openqasm += 'barrier '
2481-
for q in self.line_labels[:-1]:
2482-
openqasm += 'q[{0}], '.format(str(qubit_conversion[q]))
2483-
openqasm += 'q[{0}];\n'.format(str(qubit_conversion[self.line_labels[-1]]))
2484-
# openqasm += ';'
2494+
# Add in a barrier after every circuit layer if block_between_layers==True.
2495+
# Including barriers is critical for QCVV testing, circuits should usually
2496+
# experience minimal "behind-the-scenes" compilation (beyond necessary
2497+
# conversion to native instructions).
2498+
# To do: Add "barrier" as native pygsti circuit instruction, and use for indicating
2499+
# where pragma blocks should be.
2500+
if block_between_layers:
2501+
openqasm += 'barrier '
2502+
for q in self.line_labels[:-1]:
2503+
openqasm += 'q[{0}], '.format(str(qubit_conversion[q]))
2504+
openqasm += 'q[{0}];\n'.format(str(qubit_conversion[self.line_labels[-1]]))
2505+
# openqasm += ';'
24852506

24862507
# Add in a measurement at the end.
24872508
for q in self.line_labels:

packages/pygsti/tools/internalgates.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -296,10 +296,10 @@ def get_standard_gatenames_openqasm_conversions():
296296
std_gatenames_to_qasm['Gxpi2'] = 'u3(1.570796326794897, 4.71238898038469, 1.570796326794897)' # [1, 3, 1] * pi/2
297297
std_gatenames_to_qasm['Gxmpi2'] = 'u3(1.570796326794897, 1.570796326794897, 4.71238898038469)' # [1, 1, 3] * pi/2
298298
std_gatenames_to_qasm['Gxpi'] = 'x'
299-
std_gatenames_to_qasm['Gzpi2'] = 'u3(0., 0., 1.570796326794897)' # [0, 0, 1] * pi/2
300-
std_gatenames_to_qasm['Gzmpi2'] = 'u3(0., 0., 4.71238898038469)' # [0, 0, 3] * pi/2
299+
std_gatenames_to_qasm['Gzpi2'] = 'u3(0, 0, 1.570796326794897)' # [0, 0, 1] * pi/2
300+
std_gatenames_to_qasm['Gzmpi2'] = 'u3(0, 0, 4.71238898038469)' # [0, 0, 3] * pi/2
301301
std_gatenames_to_qasm['Gzpi'] = 'z'
302-
std_gatenames_to_qasm['Gypi2'] = 'u3(1.570796326794897, 0. 0.)' # [1, 0, 0] * pi/2
302+
std_gatenames_to_qasm['Gypi2'] = 'u3(1.570796326794897, 0, 0)' # [1, 0, 0] * pi/2
303303
std_gatenames_to_qasm['Gympi2'] = 'u3(1.570796326794897, 3.141592653589793, 3.141592653589793)' # [1, 2, 2] * pi/2
304304
std_gatenames_to_qasm['Gypi'] = 'y'
305305
std_gatenames_to_qasm['Gp'] = 's'
@@ -311,30 +311,30 @@ def get_standard_gatenames_openqasm_conversions():
311311
std_gatenames_to_qasm['Gcnot'] = 'cx'
312312
std_gatenames_to_qasm['Gswap'] = 'swap'
313313

314-
std_gatenames_to_qasm['Gc0'] = 'u3(0., 0., 0.)' # [0, 0, 0] * pi/2 (thi is Gi)
315-
std_gatenames_to_qasm['Gc1'] = 'u3(1.570796326794897, 0., 1.570796326794897)' # [1, 0, 1] * pi/2
314+
std_gatenames_to_qasm['Gc0'] = 'u3(0, 0, 0)' # [0, 0, 0] * pi/2 (thi is Gi)
315+
std_gatenames_to_qasm['Gc1'] = 'u3(1.570796326794897, 0, 1.570796326794897)' # [1, 0, 1] * pi/2
316316
std_gatenames_to_qasm['Gc2'] = 'u3(1.570796326794897, 1.570796326794897, 3.141592653589793)' # [1, 1, 2] * pi/2
317-
std_gatenames_to_qasm['Gc3'] = 'u3(3.141592653589793, 0., 3.141592653589793)' # [2, 0, 2] * pi/2 (this is Gxpi)
317+
std_gatenames_to_qasm['Gc3'] = 'u3(3.141592653589793, 0, 3.141592653589793)' # [2, 0, 2] * pi/2 (this is Gxpi)
318318
std_gatenames_to_qasm['Gc4'] = 'u3(1.570796326794897, 3.141592653589793, 4.71238898038469)' # [1, 2, 3] * pi/2
319319
std_gatenames_to_qasm['Gc5'] = 'u3(1.570796326794897, 4.71238898038469, 3.141592653589793)' # [1, 3, 2] * pi/2
320-
std_gatenames_to_qasm['Gc6'] = 'u3(3.141592653589793, 0., 0.)' # [2, 0, 0] * pi/2 (this is Gypi)
320+
std_gatenames_to_qasm['Gc6'] = 'u3(3.141592653589793, 0, 0)' # [2, 0, 0] * pi/2 (this is Gypi)
321321
std_gatenames_to_qasm['Gc7'] = 'u3(1.570796326794897, 3.141592653589793, 1.570796326794897)' # [1, 2, 1] * pi/2
322322
std_gatenames_to_qasm['Gc8'] = 'u3(1.570796326794897, 4.71238898038469, 0.)' # [1, 3, 0] * pi/2
323-
std_gatenames_to_qasm['Gc9'] = 'u3(0., 0., 3.141592653589793)' # [0, 0, 2] * pi/2 (this is Gzpi)
324-
std_gatenames_to_qasm['Gc10'] = 'u3(1.570796326794897, 0., 4.71238898038469)' # [1, 0, 3] * pi/2
323+
std_gatenames_to_qasm['Gc9'] = 'u3(0, 0, 3.141592653589793)' # [0, 0, 2] * pi/2 (this is Gzpi)
324+
std_gatenames_to_qasm['Gc10'] = 'u3(1.570796326794897, 0, 4.71238898038469)' # [1, 0, 3] * pi/2
325325
std_gatenames_to_qasm['Gc11'] = 'u3(1.570796326794897, 1.570796326794897, 0.)' # [1, 1, 0] * pi/2
326326
std_gatenames_to_qasm['Gc12'] = 'u3(1.570796326794897, 0., 3.141592653589793)' # [1, 0, 2] * pi/2 (this is Gh)
327327
std_gatenames_to_qasm['Gc13'] = 'u3(1.570796326794897, 1.570796326794897, 4.71238898038469)' # [1, 1, 3] * pi/2 (this is Gxmpi2 )
328-
std_gatenames_to_qasm['Gc14'] = 'u3(0., 0., 1.570796326794897)' # [0, 0, 1] * pi/2 (this is Gzpi2 / Gp)
328+
std_gatenames_to_qasm['Gc14'] = 'u3(0, 0, 1.570796326794897)' # [0, 0, 1] * pi/2 (this is Gzpi2 / Gp)
329329
std_gatenames_to_qasm['Gc15'] = 'u3(1.570796326794897, 3.141592653589793, 3.141592653589793)' # [1, 2, 2] * pi/2 (the is Gympi2)
330330
std_gatenames_to_qasm['Gc16'] = 'u3(1.570796326794897, 4.71238898038469, 1.570796326794897)' # [1, 3, 1] * pi/2 (this is Gxpi2 )
331-
std_gatenames_to_qasm['Gc17'] = 'u3(3.141592653589793, 0., 1.570796326794897)' # [2, 0, 1] * pi/2
331+
std_gatenames_to_qasm['Gc17'] = 'u3(3.141592653589793, 0, 1.570796326794897)' # [2, 0, 1] * pi/2
332332
std_gatenames_to_qasm['Gc18'] = 'u3(1.570796326794897, 3.141592653589793, 0.)' # [1, 2, 0] * pi/2
333333
std_gatenames_to_qasm['Gc19'] = 'u3(1.570796326794897, 4.71238898038469, 4.71238898038469)' # [1, 3, 3] * pi/2
334-
std_gatenames_to_qasm['Gc20'] = 'u3(3.141592653589793, 0., 4.71238898038469)' # [2, 0, 3] * pi/2
335-
std_gatenames_to_qasm['Gc21'] = 'u3(1.570796326794897, 0., 0.)' # [1, 0, 0] * pi/2 (this is Gypi2)
334+
std_gatenames_to_qasm['Gc20'] = 'u3(3.141592653589793, 0, 4.71238898038469)' # [2, 0, 3] * pi/2
335+
std_gatenames_to_qasm['Gc21'] = 'u3(1.570796326794897, 0, 0)' # [1, 0, 0] * pi/2 (this is Gypi2)
336336
std_gatenames_to_qasm['Gc22'] = 'u3(1.570796326794897, 1.570796326794897, 1.570796326794897)' # [1, 1, 1] * pi/2
337-
std_gatenames_to_qasm['Gc23'] = 'u3(0., 0., 4.71238898038469)' # [0, 0, 3] * pi/2 (this is Gzmpi2 / Gpdag)
337+
std_gatenames_to_qasm['Gc23'] = 'u3(0, 0, 4.71238898038469)' # [0, 0, 3] * pi/2 (this is Gzmpi2 / Gpdag)
338338

339339
return std_gatenames_to_qasm
340340

0 commit comments

Comments
 (0)