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 CPhaseShiftGate with tests (#112) #114

Merged
merged 6 commits into from
Jul 28, 2021
Merged

Add CPhaseShiftGate with tests (#112) #114

merged 6 commits into from
Jul 28, 2021

Conversation

maliasadi
Copy link
Member


Context:
Add support for Controlled Phase Gate (CPhaseShift).

Description of the Change:
Implemented CPhaseShift gate mirroring existing C++ gate structures,
as well as, tested and added to the list of supported gates.

Benefits:
In quantum computing, quantum logic gates are the building blocks of quantum circuits. To make a C++ support for entire gates in pennylane-lightning, this update is adding the missing 2-qubit CPhaseShift gate support.

Possible Drawbacks:

Related GitHub Issues:
(#112) created by @mlxd

@codecov
Copy link

codecov bot commented Jul 21, 2021

Codecov Report

Merging #114 (ab6640d) into master (515166e) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #114   +/-   ##
=======================================
  Coverage   98.14%   98.14%           
=======================================
  Files           3        3           
  Lines          54       54           
=======================================
  Hits           53       53           
  Misses          1        1           
Impacted Files Coverage Δ
pennylane_lightning/lightning_qubit.py 97.95% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 515166e...ab6640d. Read the comment docs.

@josh146 josh146 requested review from mlxd and trbromley July 21, 2021 14:21
Copy link
Member

@mlxd mlxd left a comment

Choose a reason for hiding this comment

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

Thanks for the submission @maliasadi
In addition to my listed suggestions, it would also be worth adding a test-case to the Python code (see here for example).
Also, before pushing, it is worth running make format to ensure the C++ formatting conforms to the standards expected. You may need to install clang-format for this to work.

pennylane_lightning/src/Gates.cpp Outdated Show resolved Hide resolved
pennylane_lightning/src/Gates.hpp Show resolved Hide resolved
pennylane_lightning/src/Gates.cpp Show resolved Hide resolved
@maliasadi maliasadi requested a review from mlxd July 22, 2021 21:42
Copy link
Member

@mlxd mlxd left a comment

Choose a reason for hiding this comment

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

Hi @maliasadi thanks again for your work on this. I have some follow-up suggestions. Also, please be sure to run make format before committing and pushing.

tests/test_apply.py Show resolved Hide resolved
tests/test_apply.py Show resolved Hide resolved
tests/test_apply.py Show resolved Hide resolved
pennylane_lightning/src/tests/TestingUtils.hpp Outdated Show resolved Hide resolved
tests/test_apply.py Outdated Show resolved Hide resolved
@mlxd
Copy link
Member

mlxd commented Jul 23, 2021

Also, just to note, the failing tests on Ubuntu 18.04 are due to an issue with the Github actions image we use. A fix is currently under review, and should solve 2 of those test failures.

@maliasadi
Copy link
Member Author

Thank you for your suggestions @mlxd. It's weird that the formatting is failed again! 🤔
Just to let you know, I use ubuntu 18.04 and the following script to check of my changes before each commit:

make clean && \
pip install -e . && \ 
make test && \ 
make test-cpp && \
make format

They are all pass on my side. Do you have any idea why formatting fails here? Also ./bin/format utilizes a subprocess.run feature that is new in python 3.7>, so, if the system doesn't use a proper python3 version, this script will be failed. Could it be a reason here?

@mlxd
Copy link
Member

mlxd commented Jul 23, 2021

Thank you for your suggestions @mlxd. It's weird that the formatting is failed again! thinking
Just to let you know, I use ubuntu 18.04 and the following script to check of my changes before each commit:

make clean && \
pip install -e . && \ 
make test && \ 
make test-cpp && \
make format

They are all pass on my side. Do you have any idea why formatting fails here?

Ah yes, this is likely an older version of clang-format you have on your system. Certain formatting rules changed with v11+, so likely you have 10 or lower on Ubuntu 18.04.

Also ./bin/format utilizes a subprocess.run feature that is new in python 3.7>, so, if the system doesn't use a proper python3 version, this script will be failed. Could it be a reason here?

Yes, this would be expected, as the PennyLane minimum supported Python version is 3.7.

@maliasadi
Copy link
Member Author

Ah yes, this is likely an older version of clang-format you have on your system. Certain formatting rules changed with v11+, so likely you have 10 or lower on Ubuntu 18.04.

Yes, you're right! I was using clang-format-10. Thank you @mlxd! I think it's fixed now.

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 @maliasadi, this looks great! Approved! Though we should coordinate merging this with #113.

Comment on lines +9 to +10
* Add support for Controlled Phase Gate (CPhaseShift).
[(#112)](https://github.com/PennyLaneAI/pennylane-lightning/issues/112)
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
* Add support for Controlled Phase Gate (CPhaseShift).
[(#112)](https://github.com/PennyLaneAI/pennylane-lightning/issues/112)
* Add support for Controlled Phase Gate (`CPhaseShift`).
[(#114)](https://github.com/PennyLaneAI/pennylane-lightning/pull/114)

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for updating the log file! I update it only because I was asked to do before creating the pull-request.

Comment on lines +694 to +696
: shift(std::pow(M_E, CplxType(0, phi))), matrix{1, 0, 0, 0, 0, 1,
0, 0, 0, 0, 1, 0,
0, 0, 0, shift} {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe nice to have the matrix part shown in a 4x4 grid to make it visually easy to see what's going on.

Copy link
Contributor

Choose a reason for hiding this comment

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

(unless clang requires it to be like the above)

Copy link
Member Author

Choose a reason for hiding this comment

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

This is re-arranged by clang-format, indeed!

Copy link
Member

Choose a reason for hiding this comment

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

Yep, I think we may need to revisit clang formatting rules at a later date to better fix these.


void Pennylane::CPhaseShiftGate::applyGenerator(
const StateVector &state,

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

"CRX", "CRY", "CRZ", "CRot"};
const vector<string> param_gates = {
"RX", "RY", "RZ", "PhaseShift", "Rot",
"CRX", "CRY", "CRZ", "CRot", "ControlledPhaseShift"};
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
"CRX", "CRY", "CRZ", "CRot", "ControlledPhaseShift"};
"CRX", "CRY", "CRZ", "CRot", "ControlledPhaseShift"};

tests/test_apply.py Show resolved Hide resolved
@mlxd
Copy link
Member

mlxd commented Jul 28, 2021

As a follow up, I am happy to approve this too. I think it best to allow this PR be merged before #113 as the changes are significant.

@mlxd mlxd merged commit 550ee8a into PennyLaneAI:master Jul 28, 2021
@mlxd
Copy link
Member

mlxd commented Jul 28, 2021

Well done on the PR @maliasadi !

@maliasadi
Copy link
Member Author

Well done on the PR @maliasadi !

Couldn't done it without your suggestions and supports. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants