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

Refactor Gate, Operator definitions #48

Merged
merged 41 commits into from
Mar 11, 2024
Merged

Refactor Gate, Operator definitions #48

merged 41 commits into from
Mar 11, 2024

Conversation

mofeing
Copy link
Member

@mofeing mofeing commented Mar 11, 2024

This PR refactors the Gate and Operator definitions. The difference gate types (e.g. X, Swap, Ry, CZ, ...) are still Operator subtypes, but now they are concrete subtypes that implement the parameters in their fields (unlike before, where parameters where encoded as a generic parameter of the Gate type).

This change lets us create operators without assigning the site they are acting on, which should be sufficient for retrieving the array representations or some other information. With this change, the Gate and Operator types have more clear semantics: A Gate is an Operator acting somewhere (i.e. has sites).

It also provides a small macro utility @gatedecl for declaring gate types.

Closes #44

@mofeing mofeing requested a review from jofrevalles March 11, 2024 08:59
@mofeing mofeing linked an issue Mar 11, 2024 that may be closed by this pull request
@mofeing mofeing marked this pull request as draft March 11, 2024 08:59
const Pauli = Union{I,X,Y,Z}
const Phase = Union{I,Z,S,Sd,T,Td,Rz,Hz,FSim}
The `SU{N}` multi-qubit general unitary gate that can be used to represent any unitary matrix that acts on
`N` qubits. A new random `SU{N}` can be created with `rand(SU{N}, lanes...)`, where `N` is the dimension
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
`N` qubits. A new random `SU{N}` can be created with `rand(SU{N}, lanes...)`, where `N` is the dimension
`log2(N)` qubits. A new random `SU{N}` can be created with `rand(SU{N}, lanes...)`, where `N` is the dimension

The definition of SU{N} (random unitary) is that N is the number of dimensions of the operator, therefore, in the case of qubits, this would be log2(N). This is how I have seen SU defined everywhere (see in Qiskit, in some papers, ...).

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, but using N as the dimension of the matrix is super annoying. First, it doesn't tell you in how many sites it acts. Also I added a note to describe that N in our case is the number of sites, not the dimensionality.

@mofeing mofeing requested a review from Todorbsc March 11, 2024 11:28
@mofeing mofeing marked this pull request as ready for review March 11, 2024 13:47
Copy link

codecov bot commented Mar 11, 2024

Codecov Report

Attention: Patch coverage is 80.00000% with 37 lines in your changes are missing coverage. Please review.

Project coverage is 57.58%. Comparing base (45abf2f) to head (88cfb0b).

Files Patch % Lines
src/Gate.jl 77.69% 29 Missing ⚠️
src/Array.jl 84.90% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #48      +/-   ##
==========================================
+ Coverage   56.02%   57.58%   +1.55%     
==========================================
  Files           5        5              
  Lines         282      323      +41     
==========================================
+ Hits          158      186      +28     
- Misses        124      137      +13     

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

src/Array.jl Outdated Show resolved Hide resolved
src/Array.jl Show resolved Hide resolved
@mofeing mofeing merged commit 5855f65 into master Mar 11, 2024
7 checks passed
@mofeing mofeing deleted the refactor/gate branch March 11, 2024 15:46
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.

Refactor Operator and Gate types
3 participants