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 control Hadamard gate: CH #3408

Merged
merged 29 commits into from
Nov 25, 2022
Merged

Add control Hadamard gate: CH #3408

merged 29 commits into from
Nov 25, 2022

Conversation

rmoyard
Copy link
Contributor

@rmoyard rmoyard commented Nov 22, 2022

Description of the Change:

Add the control Hadamard gate CH:

  >>> ch = qml.CH(wires=[0, 1])
  >>> matrix = ch.compute_matrix()
[[ 1.          0.          0.          0.        ]
 [ 0.          1.          0.          0.        ]
 [ 0.          0.          0.70710678  0.70710678]
 [ 0.          0.          0.70710678 -0.70710678]]

@github-actions
Copy link
Contributor

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.

@codecov
Copy link

codecov bot commented Nov 22, 2022

Codecov Report

❗ No coverage uploaded for pull request base (master@4640b34). Click here to learn what that means.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##             master    #3408   +/-   ##
=========================================
  Coverage          ?   99.69%           
=========================================
  Files             ?      299           
  Lines             ?    26572           
  Branches          ?        0           
=========================================
  Hits              ?    26492           
  Misses            ?       80           
  Partials          ?        0           
Impacted Files Coverage Δ
pennylane/devices/default_mixed.py 100.00% <ø> (ø)
pennylane/devices/default_qubit.py 100.00% <ø> (ø)
pennylane/devices/null_qubit.py 100.00% <ø> (ø)
pennylane/ops/functions/is_commuting.py 100.00% <ø> (ø)
pennylane/ops/qubit/__init__.py 100.00% <ø> (ø)
pennylane/ops/qubit/attributes.py 100.00% <ø> (ø)
...nylane/transforms/optimization/pattern_matching.py 100.00% <ø> (ø)
pennylane/ops/qubit/non_parametric_ops.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

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.

one small comment on testing, but otherwise this is great!

tests/ops/qubit/test_non_parametric_ops.py Show resolved Hide resolved
tests/ops/qubit/test_non_parametric_ops.py Outdated Show resolved Hide resolved
@AlbertMitjans
Copy link
Contributor

Why not using qml.ctrl(qml.Hadamard(0), 1)? I believe the idea of the Controlled class was to avoid having to create a class for each controlled gate.

@rmoyard rmoyard merged commit ed40eaa into master Nov 25, 2022
@rmoyard rmoyard deleted the control_hadamard branch November 25, 2022 14:52
eddddddy pushed a commit that referenced this pull request Nov 25, 2022
* Add CH

* Fix test QFT

* Add changelog

* Typo

* Update tests/ops/qubit/test_non_parametric_ops.py

Co-authored-by: Matthew Silverman <matthews@xanadu.ai>

* change test

* Add hermitian test

* Add attribute and commuting

* Missing test

* typo

* Update pennylane/ops/qubit/non_parametric_ops.py

Co-authored-by: Christina Lee <christina@xanadu.ai>

* Fix label test

Co-authored-by: Matthew Silverman <matthews@xanadu.ai>
Co-authored-by: Christina Lee <christina@xanadu.ai>
eddddddy added a commit that referenced this pull request Nov 30, 2022
* Update mitigate for new returns

* Add test for coverage (when mitiq not installed)

* CMP #8: Add `Expectation` MP class (#3343)

* Add process abstract method to MeasurementProcess class

* Add TODO comment.

* Add docstring

* Add _Probability class

* Add _Sample class

* Add process method to ClassicalShadow class

* Add tests

* Remove r_dtype from argument

* Fix coverage

* TODO

* TODO

* Fix test

* Fix equal

* Fix test

* Fix equal

* Support python3.7

* Revert

* Skip python@3.7 test

* Improve sample code

* Coverage

* Add process_state method

* Add process_state method

* Add tests

* Improve tests

* Improve tests

* Add static method

* Improve code

* Add process_state method

* Remove abstract

* Coverage

* Improve code

* Add StateMeasurement and SampleMeasurement classes

* Change inheritance

* Change inheritance

* Revert

* Add changelog entry

* Add changelog entry

* Add changelog entry

* Small fix

* Small fix

* Remove dead code

* Coverage

* Clean up tests

* Fix test

* Coverage

* Add changelog entry

* Add _Expectation class

* Add changelog entry

* Coverage

* Address comments

* Change state type

* Remove error

* Small fix

* Fix types

* Remove numpy usage

* Fix types

* Fix wire_map

* Fix wire_map

* Add wire_order to process_samples

* Docstring

* Small fix

* Add wire_order to process_samples

* Add wire_order to process_samples

* Change tests

* Add wire_order to process_samples

* Add breaking change message

* Change tests

* Add wire_order to process_samples

* Change tests

* Fix tests

* Fix tests

* Update tests/measurements/test_expval.py

* Use tol

* Improve code

* Update doc/releases/changelog-dev.md

* Group lines

* CMP #9: Add `Var` MP class (#3312)

* Add process abstract method to MeasurementProcess class

* Add TODO comment.

* Add docstring

* Add _Probability class

* Add _Sample class

* Add process method to ClassicalShadow class

* Add tests

* Remove r_dtype from argument

* Fix coverage

* TODO

* TODO

* Fix test

* Fix equal

* Fix test

* Fix equal

* Support python3.7

* Revert

* Skip python@3.7 test

* Improve sample code

* Coverage

* Add process_state method

* Add process_state method

* Add tests

* Improve tests

* Improve tests

* Add static method

* Improve code

* Add process_state method

* Remove abstract

* Coverage

* Add _Var MP Class

* Improve code

* Fix tests

* Add StateMeasurement and SampleMeasurement classes

* Change inheritance

* Change inheritance

* Change inheritance

* Revert

* Add changelog entry

* Add changelog entry

* Add changelog entry

* Small fix

* Small fix

* Small fix

* Remove dead code

* Coverage

* Clean up tests

* Small fix

* Coverage

* Coverage

* Fix test

* Coverage

* Add changelog entry

* Address comments

* Change state type

* Remove error

* Small fix

* Fix types

* Remove numpy usage

* Fix types

* Fix wire_map

* Fix wire_map

* Add wire_order to process_samples

* Docstring

* Small fix

* Add wire_order to process_samples

* Add wire_order to process_samples

* Change tests

* Add wire_order to process_samples

* Add breaking change message

* Change tests

* Add wire_order to process_samples

* Change tests

* Update doc/releases/changelog-dev.md

* refactor (_Variance): ♻️ Improve code

* Remove pylint

* test (var): 🧪 Use tol.

* refactor (CMP): ♻️ Move  into  class

Co-authored-by: Jay Soni <jbsoni@uwaterloo.ca>

* Deprecate transforms.measurement_grouping (#3417)

* Add UserWarning regarding deprecation

* Add test for warning

* Update deprecation docs

* add missing blank line

* update changelog

* update changelog

* Add module documentation and explanations for the `queuing` module (#3268)

* add queuing module explanation

* skip documentation of imported objects

* Apply suggestions from code review

Co-authored-by: Matthew Silverman <matthews@xanadu.ai>

* respond to feedback

* Apply suggestions from code review

Co-authored-by: Matthew Silverman <matthews@xanadu.ai>

* thought I already made these changes.  remove copy and queue discussion

* more info

* changelog

* Update pennylane/queuing.py

Co-authored-by: Matthew Silverman <matthews@xanadu.ai>

Co-authored-by: Matthew Silverman <matthews@xanadu.ai>

* Use `convert_like` in `hamiltonian_expand` (#3339)

* covert_like

* assert the types

* minor docs

* Update output type check

* No need to check if len(res) > 0: we should definitely have results if the Hamiltonian has terms in it

* Validate `hamiltonian_expand`: don't allow Hamiltonian with no terms (#3411)

* validate input Hamiltonian

* no thewalrus just yet

* Revert "no thewalrus just yet"

This reverts commit baae20c.

* fix: TF ResourceVariable has no len attr, can't take the len of coeffs and ops; check explicit value comparison

* Revert "fix: TF ResourceVariable has no len attr, can't take the len of coeffs and ops; check explicit value comparison"

This reverts commit f5e5784.

* use qml.math.shape

* correct shape

* trigger CI

* trigger CI

* changelog

Co-authored-by: Albert Mitjans <a.mitjanscoma@gmail.com>

* Add control Hadamard gate: CH (#3408)

* Add CH

* Fix test QFT

* Add changelog

* Typo

* Update tests/ops/qubit/test_non_parametric_ops.py

Co-authored-by: Matthew Silverman <matthews@xanadu.ai>

* change test

* Add hermitian test

* Add attribute and commuting

* Missing test

* typo

* Update pennylane/ops/qubit/non_parametric_ops.py

Co-authored-by: Christina Lee <christina@xanadu.ai>

* Fix label test

Co-authored-by: Matthew Silverman <matthews@xanadu.ai>
Co-authored-by: Christina Lee <christina@xanadu.ai>

* qml.equal for Hamiltonians and Tensors (#3390)

* use singledispatch

* Different types don't match

* fix bug

* rearrange

* clean up

* add NotImplementedError test

* update docstrings

* docstrings

* tests

* fix bugs from merge conflict

* update tests

* docs and changelog

* Update pennylane/ops/functions/equal.py

Co-authored-by: Christina Lee <christina@xanadu.ai>

* Doc updates

Co-authored-by: antalszava <antalszava@gmail.com>

* Remove extra indent

Co-authored-by: antalszava <antalszava@gmail.com>

* Add specific handling for Hermitians

* Split comparing Hamiltonian and Tensor into seperate functions

* docstring for _obs_comparison_data

* add check for op2 being Observable

* Add function for PauliX/Y/Z comparisons

* update tests

* Default to original qml.equal logic if no special case

* Update changelog

* Fix tests

* generalize _equal_pauli to other Operation/Observables

* rearrange to simplify

* update tests

* add tests

* combine _equal_tensor and _obs_comparison_data

* add NotImplementedError

* update tests

Co-authored-by: Christina Lee <christina@xanadu.ai>
Co-authored-by: antalszava <antalszava@gmail.com>

* Add control CZ gate: CCZ (#3410)

* Add CCZ

* add decomp test

* Add changelog

* Typo

* update control test

* Trigger CI

* Fix test

* Update tests/gate_data.py

Co-authored-by: Matthew Silverman <matthews@xanadu.ai>

* black apply

* Black

Co-authored-by: Matthew Silverman <matthews@xanadu.ai>

* Add changelog entry

* Don't stack results

* Fix and add tests

Co-authored-by: Albert Mitjans <a.mitjanscoma@gmail.com>
Co-authored-by: Jay Soni <jbsoni@uwaterloo.ca>
Co-authored-by: lillian542 <38584660+lillian542@users.noreply.github.com>
Co-authored-by: Christina Lee <christina@xanadu.ai>
Co-authored-by: Matthew Silverman <matthews@xanadu.ai>
Co-authored-by: antalszava <antalszava@gmail.com>
Co-authored-by: Romain Moyard <rmoyard@gmail.com>
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.

4 participants