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

Two qubit observable #192

merged 7 commits into from May 13, 2019


None yet
2 participants
Copy link

commented May 4, 2019

Description of the Change:

This PR adds support for expectation values of two-qubit Hermitian operators and implements it for default_qubit plugin. This is the implementation suggested by @josh146 in the discussion and answering @bencbartlett


We can slowly think of supporting this for CV and then extending to an arbitrary gate, e.g., Toffoli.

Possible Drawbacks:
Plugins should support multi-qubit operators too. In some cases there might be a neat trick with a change of basis which allows this as @josh146 explains for the Rigetti systems.

Related GitHub Issues:

@ghost ghost assigned quantshah May 4, 2019

@ghost ghost added the review label May 4, 2019


This comment has been minimized.

Copy link

commented May 4, 2019

Codecov Report

Merging #192 into master will not change coverage.
The diff coverage is 100%.

@@          Coverage Diff          @@
##           master   #192   +/-   ##
  Coverage     100%   100%           
  Files          28     28           
  Lines        1686   1689    +3     
+ Hits         1686   1689    +3
Impacted Files Coverage Δ
pennylane/plugins/ 100% <100%> (ø) ⬆️
pennylane/expval/ 100% <100%> (ø) ⬆️

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 bc9ed12...4db37ff. Read the comment docs.

@@ -156,7 +156,7 @@ class Hermitian(Expectation):
A (array): square hermitian matrix.
wires (Sequence[int] or int): the wire the operation acts on

This comment has been minimized.

Copy link

josh146 May 6, 2019


It doesn't let me leave a comment up above, but let's make clear in the docstring that expval.Hermitian now accepts N^2\times N^2 Hermitian matrix, acting on N wires. These docstrings act as the 'ground truth' for plugin developers to ensure they implement the correct conventions.

Show resolved Hide resolved pennylane/expval/ Outdated
Show resolved Hide resolved tests/ Outdated
Copy link

left a comment

This is great, thanks @quantshah! This is merge-ready, barring some small changes to the Hermitian expectation docstring, and a minor test change.

quantshah added some commits May 11, 2019

@quantshah quantshah requested a review from josh146 May 11, 2019


This comment has been minimized.

Copy link
Collaborator Author

commented May 11, 2019

I guess this takes care of the qubit case. Now on to the CV observable for multi-mode expectation.

I will port to pytest after this is merged.

@josh146 josh146 merged commit 63acb1a into XanaduAI:master May 13, 2019

4 checks passed

CodeFactor No issues found.
Travis CI - Pull Request Build Passed
codecov/patch 100% of diff hit (target 100%)
codecov/project 100% (+0%) compared to bc9ed12

@ghost ghost removed the review label May 13, 2019

@quantshah quantshah deleted the quantshah:multi-exp branch May 13, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.