Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ECR support to QASM translation #457

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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