-
Notifications
You must be signed in to change notification settings - Fork 123
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
Register: Refactor #17
Conversation
Exported APIs
Note: we don't export |
Pull Request Test Coverage Report for Build 56
💛 - Coveralls |
src/Register.jl
Outdated
Abstract type for quantum registers, all quantum registers supports | ||
the interface of julia arrays. | ||
Abstract type for quantum registers, all quantum registers contains a | ||
subtype of `AbstractArray` as member `state`. | ||
|
||
## Parameters | ||
- `M` is the number of qubits |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
M -> N
function Register(state::Array{T, 2}) where T | ||
len, nbatch = size(state) | ||
ispow2(len) || throw(Compat.InexactError(:Register, Register, state)) | ||
N = log2i(len) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this realization of log2i is much better: https://groups.google.com/forum/#!topic/julia-users/YaACmwePGxM
src/Register.jl
Outdated
|
||
pack `ids` together to the first k-dimensions. | ||
pack `orders` together to the first k-dimensions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name pack is too short, and not intuitive, make it longer, like change_order.
src/Register.jl
Outdated
|
||
# set default type | ||
zero_state(nqubit::Int, nbatch::Int=1) = zero_state(Complex128, nqubit, nbatch) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep parameters in order nqubit, nbatch, T
, otherwise confusing to users.
By the way, multiple T
is not needed. Just fix the datatype to complex128, otherwise, you need to cope with data type conversion (not worthy).
data::Array{T, N} | ||
ids::Vector{Int} | ||
mutable struct Register{N, B, T} <: AbstractRegister{N, B, T} | ||
state::Array{T, 2} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a mistake, now I think rank-3 tensor makes more sense, because in this way, the array shape contains all informations about qubit and batch. otherwise, we can not distinguish remaining dimension and batch dimension without query the register.
src/Register.jl
Outdated
remained_size = 2^(M-K) | ||
data = reshape(src.data, exposed_size, remained_size) | ||
Register(M, 1, data, src.ids) | ||
exposed_size(orders::NTuple{K, Int}) where K = 2^K |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nexposed_qubit, since you have nqubit API, it is more natural way to design API.
use 1<<n instead of 2^K! about 5 times faster!
Codecov Report
@@ Coverage Diff @@
## master #17 +/- ##
==========================================
+ Coverage 96.11% 96.77% +0.65%
==========================================
Files 3 3
Lines 103 62 -41
==========================================
- Hits 99 60 -39
+ Misses 4 2 -2
Continue to review full report at Codecov.
|
Update for new Multigraph backend
Basics
AbstractRegister
is no more a subtype ofAbstractArray
. (array interface is removed)Default Register
ids
toline_orders
(address
would be better?)data
tostate
Register
stores the state as anArray{T, 2}
(previously we allow arbitraryArray{T, N}
)zero_state
,rand_state
Packing and Focusing
pack!
methods only take one instance ofRegister
.pack!
is optimized for contiguous memory, but there is still problems [Register] Optimization for contiguous address (line orders) #16focus!
now has side-effect, rename it fromfocus
focus!
andpack!
supports mixed range like(2, 5, 6:7, 9, 10)