Skip to content

Fix factor of 2 in Rz operator in trotter_export_to_qgates_test.py#1380

Open
arettig wants to merge 1 commit into
quantumlib:mainfrom
arettig:trotter_qasm2
Open

Fix factor of 2 in Rz operator in trotter_export_to_qgates_test.py#1380
arettig wants to merge 1 commit into
quantumlib:mainfrom
arettig:trotter_qasm2

Conversation

@arettig

@arettig arettig commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Fixes #721 (supersedes #1343). A factor of 2 error in Rz gates is corrected when outputting a Trotter decomposition to QASM (for both the controlled and uncontrolled versions). The corresponding tests are also corrected.

A factor of 2 discrepancy between the definition of the Rz(theta)
operator is corrected when exporting to QASM format.
@arettig arettig added the priority/before-1.7.2 Things to do before the next release label Jun 25, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the coefficient calculations for the C-Phase and Rz gates generated in pauli_exp_to_qasm within trotter_exp_to_qgates.py. Specifically, it doubles the coefficient for the Rz gate when no ancilla is used, and flips the signs for C-Phase and Rz gates when an ancilla is used. Corresponding unit tests in trotter_exp_to_qgates_test.py have been updated to reflect these new coefficient values. No review comments were provided, so there is no feedback to address.

@mhucka

mhucka commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator

It's weird how Gemini Code Assist is all over some PRs, and other ones it just kinda wipes its hands and says "eh, not my concern."

@mhucka mhucka left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this. I have some comments that are not critical, so I approved the PR and will leave it to you to address them (or not) before merging.

Comment on lines 249 to 255
ret_list = ret_list + [
"Rz {} {}".format(1 * term_coeff * evolution_time, ancilla)
"Rz {} {}".format(-1 * term_coeff * evolution_time, ancilla)
]
else:
ret_list = ret_list + [
"Rz {} {}".format(1 * term_coeff * evolution_time, ancilla)
"Rz {} {}".format(-1 * term_coeff * evolution_time, ancilla)
]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this code duplication be avoided somehow?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I'm not sure the -1 part is needed. It should work to write the more idiomatic form

-term_coeff * evolution_time

unless there's a reason for human readability or something else?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more thing: instead of somelist + [something], it's more efficient to do somelist.append(something). The + operator creates a new copy of the list, which append avoids.

However, if the rest of the file has many more instances of the same style of construct (ret_list = rel_list + […]), then I would say it's better to do what you did here and keep the same pattern. A separate PR can fix the inefficient constructs (and do it for other files, because if it happens here it probably happens elsewhere in the code base).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority/before-1.7.2 Things to do before the next release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Angle of rotation in trotterize_exp_qubop_to_qasm is off by a factor of 2

2 participants