Skip to content

Commit

Permalink
Merge pull request #457 from sandialabs/bugfix-ecr-qasm
Browse files Browse the repository at this point in the history
Add ECR support to QASM translation
  • Loading branch information
sserita authored Jul 22, 2024
2 parents 115df93 + 15db435 commit 702ebb9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pygsti/circuits/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -4250,6 +4250,9 @@ def convert_to_openqasm(self, num_qubits=None,
# Include a delay instruction
openqasm += 'opaque delay(t) q;\n\n'

# Add a template for ECR commands that we will replace/remove later
openqasm += "ECRPLACEHOLDER"

openqasm += 'qreg q[{0}];\n'.format(str(num_qubits))
# openqasm += 'creg cr[{0}];\n'.format(str(num_qubits))
openqasm += 'creg cr[{0}];\n'.format(str(num_qubits + num_IMs))
Expand Down Expand Up @@ -4349,6 +4352,13 @@ def convert_to_openqasm(self, num_qubits=None,
# openqasm += "measure q[{0}] -> cr[{1}];\n".format(str(qubit_conversion[q]), str(qubit_conversion[q]))
openqasm += "measure q[{0}] -> cr[{1}];\n".format(str(qubit_conversion[q]),
str(num_IMs_used + qubit_conversion[q]))

# Replace ECR placeholder
ecr_replace_str = ""
if 'ecr' in openqasm:
ecr_replace_str = "gate rzx(param0) q0,q1 { h q1; cx q0,q1; rz(param0) q1; cx q0,q1; h q1; }\n"
ecr_replace_str += "gate ecr q0,q1 { rzx(pi/4) q0,q1; x q0; rzx(-pi/4) q0,q1; }\n\n"
openqasm = openqasm.replace("ECRPLACEHOLDER", ecr_replace_str)

return openqasm

Expand Down
4 changes: 4 additions & 0 deletions pygsti/tools/internalgates.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,8 @@ def standard_gatenames_openqasm_conversions(version='u3'):
std_gatenames_to_qasm['Gc22'] = ['u3(1.570796326794897, 1.570796326794897, 1.570796326794897)'] # [1,1,1]*pi/2
std_gatenames_to_qasm['Gc23'] = ['u3(0, 0, 4.71238898038469)'] # [0, 0, 3] * pi/2 (this is Gzmpi2 / Gpdag)

std_gatenames_to_qasm['Gecr'] = ['ecr']

std_gatenames_to_argmap = {}
std_gatenames_to_argmap['Gzr'] = lambda gatearg: ['u3(0, 0, ' + str(gatearg[0]) + ')']
std_gatenames_to_argmap['Gczr'] = lambda gatearg: ['crz(' + str(gatearg[0]) + ')']
Expand Down Expand Up @@ -782,6 +784,8 @@ def standard_gatenames_openqasm_conversions(version='u3'):
std_gatenames_to_qasm['Gt'] = ['rz(0.7853981633974485)']
std_gatenames_to_qasm['Gtdag'] = ['rz(5.497787143782138)']

std_gatenames_to_qasm['Gecr'] = ['ecr']

std_gatenames_to_argmap = {}
std_gatenames_to_argmap['Gzr'] = lambda gatearg: ['rz(' + str(gatearg[0]) + ')']
std_gatenames_to_argmap['Gczr'] = lambda gatearg: ['crz(' + str(gatearg[0]) + ')']
Expand Down

0 comments on commit 702ebb9

Please sign in to comment.