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

Transform for Clifford+T decomposition #4655

Closed
wants to merge 58 commits into from

Conversation

obliviateandsurrender
Copy link
Contributor

Context: Adds a transform to perform Clifford+T decomposition

Description of the Change: Unrolls the circuit into Clifford+Rotation basis and then uses the functionality to obtain approximations for arbitrary z-rotations up to arbitrary ϵ for the operations.

Benefits: Allows one to transform any random circuit to a Clifford+Phase basis.

Possible Drawbacks: Might be sub-optimal

Related GitHub Issues:

@github-actions
Copy link
Contributor

github-actions bot commented Oct 6, 2023

Hello. You may have forgotten to update the changelog!
Please edit doc/releases/changelog-dev.md with:

  • A one-to-two sentence description of the change. You may include a small working example for new features.
  • A link back to this PR.
  • Your name (or GitHub username) in the contributors section.

@obliviateandsurrender
Copy link
Contributor Author

[sc-43354]

@codecov
Copy link

codecov bot commented Oct 6, 2023

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (c899d6d) 99.64% compared to head (73b5f6e) 99.63%.
Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4655      +/-   ##
==========================================
- Coverage   99.64%   99.63%   -0.01%     
==========================================
  Files         380      382       +2     
  Lines       34275    34260      -15     
==========================================
- Hits        34154    34136      -18     
- Misses        121      124       +3     
Files Coverage Δ
pennylane/__init__.py 100.00% <ø> (ø)
pennylane/transforms/__init__.py 100.00% <100.00%> (ø)
...nsforms/decompositions/clifford_plus_t/__init__.py 100.00% <100.00%> (ø)
...lane/transforms/optimization/optimization_utils.py 100.00% <100.00%> (ø)
...ompositions/clifford_plus_t/cliffordt_transform.py 98.96% <98.96%> (ø)

... and 45 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@trbromley trbromley left a comment

Choose a reason for hiding this comment

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

Thanks @obliviateandsurrender! Let me know if I can help clarify any of the comments.

Copy link
Contributor

@DSGuala DSGuala left a comment

Choose a reason for hiding this comment

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

Reviewed docs. Will look at code now.

pennylane/transforms/__init__.py Outdated Show resolved Hide resolved

Args:
qfunc (function): A quantum function
max_depth (int): The depth to use for tape expansion before manual decomposition to Clifford+T basis is applied
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
max_depth (int): The depth to use for tape expansion before manual decomposition to Clifford+T basis is applied
max_depth (int): How many times the tape is expanded before manual decomposition to Clifford+T basis is applied

Also, what does manual decomposition mean here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It means the actual decomposition to the Clifford+T basis.

Comment on lines +313 to +314
Keyword Args:
Arguments (*):
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks kind of strange in the preview. Could it just say "Keyword Args:" and not include "Arguments (*):"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am doing so to escape making a big list of kwargs for individual items. I couldn't find another way to do it.

Args:
qfunc (function): A quantum function
max_depth (int): The depth to use for tape expansion before manual decomposition to Clifford+T basis is applied
method (str): Method to be used for Clifford+T decomposition. Default value is ``"sk"`` for Solovay-Kitaev
Copy link
Contributor

Choose a reason for hiding this comment

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

Solovay-Kitaev is the only method for now, but planning to add the other one later?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, at least I hope so!

ValueError: If any gate operation does not have any existing rule for its decomposition
NotImplementedError: If chosen decomposition is not supported

.. seealso:: :func:`~.sk_decomposition` and :func:`~.sk_approximate_set`
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we also have an example? 🙏

Copy link
Contributor

@timmysilv timmysilv left a comment

Choose a reason for hiding this comment

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

mostly looks good! i have a weird feeling that we're missing some testing to be sure it's totally ready but it's not coming to me

next_gate_idx = find_next_gate(curr_gate.wires, copied_ops[1:])

# Replace the current gate, add it to merged list and pop it from orginal one
merged_ops.append(curr_gate.__class__(*cumulative_angles, wires=curr_gate.wires))
Copy link
Contributor

Choose a reason for hiding this comment

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

this is probably better for this use-case, but in general you may want to use bind_new_parameters


matrix_op = reduce(
lambda x, y: x @ y, [qml.matrix(op) for op in decomp_ops][::-1]
) * qml.matrix(global_ops)
Copy link
Contributor

Choose a reason for hiding this comment

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

should it not be this?

Suggested change
) * qml.matrix(global_ops)
) @ qml.matrix(global_ops)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The matrix for GlobalPhase is like this ([[phase]]), so I think the latter would throw an error.

@trbromley trbromley added the do not merge ⚠️ Do not merge the pull request until this label is removed label Oct 20, 2023
@trbromley trbromley closed this Oct 20, 2023
@mlxd mlxd deleted the clifford+t_tranform branch October 20, 2023 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do not merge ⚠️ Do not merge the pull request until this label is removed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants