Skip to content

Commit 702ebb9

Browse files
authored
Merge pull request #457 from sandialabs/bugfix-ecr-qasm
Add ECR support to QASM translation
2 parents 115df93 + 15db435 commit 702ebb9

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

pygsti/circuits/circuit.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4250,6 +4250,9 @@ def convert_to_openqasm(self, num_qubits=None,
42504250
# Include a delay instruction
42514251
openqasm += 'opaque delay(t) q;\n\n'
42524252

4253+
# Add a template for ECR commands that we will replace/remove later
4254+
openqasm += "ECRPLACEHOLDER"
4255+
42534256
openqasm += 'qreg q[{0}];\n'.format(str(num_qubits))
42544257
# openqasm += 'creg cr[{0}];\n'.format(str(num_qubits))
42554258
openqasm += 'creg cr[{0}];\n'.format(str(num_qubits + num_IMs))
@@ -4349,6 +4352,13 @@ def convert_to_openqasm(self, num_qubits=None,
43494352
# openqasm += "measure q[{0}] -> cr[{1}];\n".format(str(qubit_conversion[q]), str(qubit_conversion[q]))
43504353
openqasm += "measure q[{0}] -> cr[{1}];\n".format(str(qubit_conversion[q]),
43514354
str(num_IMs_used + qubit_conversion[q]))
4355+
4356+
# Replace ECR placeholder
4357+
ecr_replace_str = ""
4358+
if 'ecr' in openqasm:
4359+
ecr_replace_str = "gate rzx(param0) q0,q1 { h q1; cx q0,q1; rz(param0) q1; cx q0,q1; h q1; }\n"
4360+
ecr_replace_str += "gate ecr q0,q1 { rzx(pi/4) q0,q1; x q0; rzx(-pi/4) q0,q1; }\n\n"
4361+
openqasm = openqasm.replace("ECRPLACEHOLDER", ecr_replace_str)
43524362

43534363
return openqasm
43544364

pygsti/tools/internalgates.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,8 @@ def standard_gatenames_openqasm_conversions(version='u3'):
729729
std_gatenames_to_qasm['Gc22'] = ['u3(1.570796326794897, 1.570796326794897, 1.570796326794897)'] # [1,1,1]*pi/2
730730
std_gatenames_to_qasm['Gc23'] = ['u3(0, 0, 4.71238898038469)'] # [0, 0, 3] * pi/2 (this is Gzmpi2 / Gpdag)
731731

732+
std_gatenames_to_qasm['Gecr'] = ['ecr']
733+
732734
std_gatenames_to_argmap = {}
733735
std_gatenames_to_argmap['Gzr'] = lambda gatearg: ['u3(0, 0, ' + str(gatearg[0]) + ')']
734736
std_gatenames_to_argmap['Gczr'] = lambda gatearg: ['crz(' + str(gatearg[0]) + ')']
@@ -782,6 +784,8 @@ def standard_gatenames_openqasm_conversions(version='u3'):
782784
std_gatenames_to_qasm['Gt'] = ['rz(0.7853981633974485)']
783785
std_gatenames_to_qasm['Gtdag'] = ['rz(5.497787143782138)']
784786

787+
std_gatenames_to_qasm['Gecr'] = ['ecr']
788+
785789
std_gatenames_to_argmap = {}
786790
std_gatenames_to_argmap['Gzr'] = lambda gatearg: ['rz(' + str(gatearg[0]) + ')']
787791
std_gatenames_to_argmap['Gczr'] = lambda gatearg: ['crz(' + str(gatearg[0]) + ')']

0 commit comments

Comments
 (0)