Skip to content

Commit 992394b

Browse files
authored
Support for arbitrary element types and sparse matrices (#108)
* support for arvitrary element types * add sparse matrix support * reformat * more tests * reformat * Prepare v0.7.0 release * Only patch version change * update docs
1 parent cc74f13 commit 992394b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2892
-1563
lines changed

Project.toml

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,48 @@
11
name = "QuantumInformation"
22
uuid = "3c0b384b-479c-5684-b2ef-9d7a46dd931e"
3+
version = "0.5.1"
34
authors = ["Dariusz Kurzyk <dkurzyk@iitis.pl>", "Łukasz Pawela <lpawela@iitis.pl>", "Piotr Gawron <gawron@iitis.pl>", "Marcin Przewięźlikowski <m.przewie@gmail.com>"]
4-
version = "0.5.0"
55

66
[deps]
7+
Arpack = "7d9fca2a-8960-54d3-9f78-7d1dccf2cb97"
78
Convex = "f65535da-76fb-5f13-bab9-19810c17039a"
89
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
910
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1011
MatrixEnsembles = "c7015dd7-3fb7-4a4c-827e-526313618491"
1112
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1213
SCS = "c946c3f1-0d1f-5ce8-9dea-7daa1f7e2d13"
14+
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1315
TensorCast = "02d47bb6-7ce6-556a-be16-bb1710789e2b"
1416
TensorOperations = "6aa20fa7-93e2-5fca-9bc0-fbd0db3c71a2"
1517

1618
[compat]
19+
Aqua = "0.8"
20+
Arpack = "0.5.4"
1721
Convex = "0.13.7, 0.14, 0.15, 0.16"
1822
DocStringExtensions = "0.8.3, 0.9"
19-
MatrixEnsembles = "0.1"
23+
DoubleFloats = "1.5.0"
24+
JET = "0.9, 0.10, 0.11"
25+
LinearAlgebra = "1"
26+
MatrixEnsembles = "0.2"
27+
Pkg = "1"
28+
PrecompileTools = "1"
29+
Random = "1"
2030
SCS = "1.1.0, 2, 3"
31+
SparseArrays = "1"
2132
StatsBase = "0.33.2, 0.34"
22-
PrecompileTools = "1"
2333
TensorCast = "0.4"
2434
TensorOperations = "4"
25-
julia = "1.7"
26-
Aqua = "0.8"
27-
JET = "0.9, 0.10, 0.11"
28-
SparseArrays = "1"
2935
Test = "1"
30-
LinearAlgebra = "1"
31-
Pkg = "1"
32-
Random = "1"
36+
julia = "1.7"
3337

3438
[extras]
3539
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
40+
DoubleFloats = "497a8b3b-efae-58df-a0af-a86822472b78"
3641
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
3742
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
38-
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
43+
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
3944
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
4045
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
41-
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
4246

4347
[targets]
44-
test = ["Aqua", "JET", "Pkg", "SparseArrays", "StatsBase", "Test", "PrecompileTools"]
48+
test = ["Aqua", "JET", "Pkg", "StatsBase", "Test", "PrecompileTools", "DoubleFloats"]

bench.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ end
1414
bench_device()
1515
bench_device()
1616
bench_cpu()
17-
bench_cpu()
17+
bench_cpu()

docs/build.jl

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,27 @@ cd(dirname(@__FILE__)) do
1818
include("../examples/ex1.jl")
1919

2020
# Generate and save the contents of docstrings as markdown files.
21-
index = Index()
21+
index = Index()
2222
for mod in modules
2323
update!(index, save(joinpath(api_directory, "$(mod).md"), mod))
2424
end
25-
save(joinpath(api_directory, "index.md"), index; md_subheader = :category)
25+
save(joinpath(api_directory, "index.md"), index; md_subheader=:category)
2626

2727
# Add a reminder not to edit the generated files.
2828
open(joinpath(api_directory, "README.md"), "w") do f
29-
print(f, """
30-
Files in this directory are generated using the `build.jl` script. Make
31-
all changes to the originating docstrings/files rather than these ones.
32-
Documentation should *only* be built directly on the `master` branch.
33-
Source links would otherwise become unavailable should a branch be
34-
deleted from the `origin`. This means potential pull request authors
35-
*should not* run the build script when filing a PR.
36-
""")
29+
return print(
30+
f,
31+
"""
32+
Files in this directory are generated using the `build.jl` script. Make
33+
all changes to the originating docstrings/files rather than these ones.
34+
Documentation should *only* be built directly on the `master` branch.
35+
Source links would otherwise become unavailable should a branch be
36+
deleted from the `origin`. This means potential pull request authors
37+
*should not* run the build script when filing a PR.
38+
""",
39+
)
3740
end
3841

3942
info("Adding all documentation changes in $(api_directory) to this commit.")
40-
success(`git add $(api_directory)`) || exit(1)
43+
return success(`git add $(api_directory)`) || exit(1)
4144
end

docs/make.jl

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
using Documenter, QuantumInformation
22

3-
format = Documenter.HTML(edit_link = "master",
4-
prettyurls = get(ENV, "CI", nothing) == "true",
5-
assets = ["assets/favicon.ico"],
3+
format = Documenter.HTML(
4+
edit_link="master",
5+
prettyurls=get(ENV, "CI", nothing) == "true",
6+
assets=["assets/favicon.ico"],
67
)
78

89
makedocs(
9-
clean = true,
10-
format = format,
11-
sitename = "QuantumInformation.jl",
12-
authors = "Piotr Gawron, Dariusz Kurzyk, Łukasz Pawela",
13-
14-
pages = [
10+
clean=true,
11+
format=format,
12+
sitename="QuantumInformation.jl",
13+
authors="Piotr Gawron, Dariusz Kurzyk, Łukasz Pawela",
14+
pages=[
1515
"Home" => "index.md",
1616
"Manual" => Any[
1717
"man/quickstart.md",
@@ -20,9 +20,9 @@ makedocs(
2020
"man/functionals.md",
2121
"man/measurement.md",
2222
"man/channels.md",
23-
"man/random.md"
23+
"man/random.md",
2424
],
25-
"Library" => "lib/QuantumInformation.md"
25+
"Library" => "lib/QuantumInformation.md",
2626
# Any[
2727
# "lib/QuantumInformation.md",
2828
# "lib/content/base.md",
@@ -31,11 +31,7 @@ makedocs(
3131
# "lib/content/randomstate.md",
3232
# "lib/content/utils.md"
3333
# ]
34-
]
34+
],
3535
)
3636

37-
deploydocs(
38-
39-
target = "build",
40-
repo = "github.com/iitis/QuantumInformation.jl.git"
41-
)
37+
deploydocs(target="build", repo="github.com/iitis/QuantumInformation.jl.git")

docs/src/man/channels.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ Also, channels object are callable
2525
Φ(ρ)
2626
```
2727

28+
Additionally, `SuperOperator` can be constructed directly from a Julia function:
29+
```@repl QuantumInformation
30+
ρ = [0.25 0.25im; -0.25im 0.75]
31+
Ψ = SuperOperator(x -> ρ*x*ρ, 2, 2)
32+
```
33+
34+
2835
## Channel Representations
2936

3037
Channels can be represented in various bases. The `channelbasis` function generates a basis for quantum channels, which can then be used with `represent` to find the coefficients of a channel in that basis, or `combine` to reconstruct the channel from coefficients.

docs/src/man/examples.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@ $100$ random pure initial states. We also check how the parameter $\gamma$
3232
influences this fidelity.
3333

3434
```@repl QuantumInformation
35+
using Statistics
3536
steps = 100
3637
haar = HaarKet(2)
37-
ψ = (ket(0, 4) + ket(3, 4))/sqrt(2)
38+
ψ = (ket(1, 4) + ket(4, 4))/sqrt(2)
3839
γs = 0.0:0.01:1.0
3940
Φ = KrausOperators([[1 0; 0 sqrt(1-γ)], [0 sqrt(γ); 0 0]])
40-
post = [PostSelectionMeasurement(proj(ket(i, 4)) ⊗ eye(2)) for i=0:3]
41-
rots = [UnitaryChannel(eye(2)), UnitaryChannel(sx), UnitaryChannel(sz),
41+
post = [PostSelectionMeasurement(proj(ket(i, 4)) ⊗ 𝕀(2)) for i=1:4]
42+
rots = [UnitaryChannel(𝕀(2)), UnitaryChannel(sx), UnitaryChannel(sz),
4243
UnitaryChannel(sx*sz)]
4344
had = UnitaryChannel{Matrix{ComplexF64}}(hadamard(2))
4445
cnot = UnitaryChannel{Matrix{ComplexF64}}([1 0 0 0; 0 1 0 0; 0 0 0 1; 0 0 1 0])
@@ -55,5 +56,5 @@ IdentityChannel(2))∘(IdentityChannel(4) ⊗ Φ))(ξ)
5556
end
5657
end
5758
end
58-
mean(r, 1)
59+
mean(r, dims=1)
5960
```

docs/src/man/functionals.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,29 @@ $C(\rho)=0$, then $\rho$ is separable.
184184
concurrence(ρ ⊗ σ)
185185
concurrence(proj(max_entangled(4)))
186186
```
187+
188+
## Sparse Matrix Support
189+
190+
Many functionals in **QuantumInformation.jl** provide native support for sparse matrices. For large systems (typically larger than 32x32), we utilize iterative solvers from [Arpack.jl](https://github.com/JuliaLinearAlgebra/Arpack.jl) to efficiently compute a subset of eigenvalues or singular values.
191+
192+
The following functionals have optimized sparse implementations:
193+
- `norm_trace`
194+
- `fidelity_sqrt`
195+
- `vonneumann_entropy`
196+
- `renyi_entropy`
197+
- `relative_entropy`
198+
- `negativity`
199+
- `ppt`
200+
201+
```@example QuantumInformation
202+
using SparseArrays
203+
n = 6
204+
d = n^2
205+
ψ = max_entangled(SparseVector{ComplexF64, Int}, d)
206+
ρ = proj(ψ)
207+
negativity(ρ, [n, n], 1)
208+
```
209+
210+
> [!NOTE]
211+
> For very large or high-rank sparse matrices, iterative solvers may have convergence issues or miss small eigenvalues. We cap the number of computed values at 32 for performance and stability.
212+

docs/src/man/states.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ max_mixed(4)
6161
werner_state(4, 0.4)
6262
```
6363

64+
For identity transformations, the library provides the `𝕀` (or `identity_gate`) function:
65+
```@repl QuantumInformation
66+
𝕀(2)
67+
```
68+
69+
6470
## Non-standard matrix transformations
6571
We will now introduce
6672
reshaping operators, which map matrices to vectors and vice versa. We start with
@@ -134,6 +140,11 @@ The `permutesystems` function allows permuting subsystems of a composite quantum
134140
permutesystems(ρ, [2, 2], [2, 1])
135141
```
136142

143+
## Sparse matrix support
144+
145+
Many of these transformations natively support sparse matrices from the `SparseArrays` library. Functions such as `ptrace`, `ptranspose`, `reshuffle`, and `permutesystems` have been optimized to return sparse results when given sparse inputs, preserving memory for large quantum systems.
146+
147+
137148

138149
## Channels
139150

0 commit comments

Comments
 (0)