Skip to content

Commit a50c1ae

Browse files
authored
Merge branch 'master' into feature/normalize-for-canonical
2 parents 44c236a + 0c2ad3e commit a50c1ae

16 files changed

+210
-137
lines changed

.github/workflows/CI.yml

+47-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
include-all-prereleases: true
4949
- uses: julia-actions/cache@v1
5050
with:
51-
cache-name: Unit Tests CI - Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }}
51+
cache-name: CI / ${{ matrix.test_group }} / Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }}
5252
- name: Add Julia registries
5353
run: |
5454
using Pkg
@@ -63,6 +63,52 @@ jobs:
6363
- uses: codecov/codecov-action@v3
6464
with:
6565
files: lcov.info
66+
python:
67+
name: ${{ matrix.test_group }} / Julia ${{ matrix.version }}
68+
runs-on: ubuntu-latest
69+
strategy:
70+
fail-fast: false
71+
matrix:
72+
version:
73+
- '1'
74+
test_group:
75+
- python
76+
os:
77+
- ubuntu-latest
78+
arch:
79+
- x64
80+
steps:
81+
- uses: actions/checkout@v4
82+
- uses: julia-actions/setup-julia@v1
83+
with:
84+
version: ${{ matrix.version }}
85+
arch: ${{ matrix.arch }}
86+
include-all-prereleases: true
87+
- uses: julia-actions/cache@v1
88+
with:
89+
cache-name: CI / ${{ matrix.test_group }} / Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }}
90+
- name: Set and export registry flavor preference
91+
run: echo "JULIA_PKG_SERVER_REGISTRY_PREFERENCE=${JULIA_PKG_SERVER_REGISTRY_PREFERENCE:-eager}" >> ${GITHUB_ENV}
92+
shell: bash
93+
- name: Add Julia registries
94+
run: |
95+
using Pkg
96+
pkg"registry add https://github.com/bsc-quantic/Registry.git"
97+
pkg"registry add General"
98+
shell: julia --color=yes {0}
99+
- name: Run tests
100+
run: |
101+
julia --color=yes --code-coverage=user --depwarn=yes --project=test/python/ -e '
102+
using Pkg
103+
Pkg.instantiate()
104+
Pkg.resolve()
105+
include("test/python/runtests.jl")'
106+
shell: bash
107+
- uses: julia-actions/julia-buildpkg@v1
108+
- uses: julia-actions/julia-processcoverage@v1
109+
- uses: codecov/codecov-action@v3
110+
with:
111+
files: lcov.info
66112
docs:
67113
name: Documentation
68114
runs-on: ubuntu-latest

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,6 @@ dist
420420
.julia
421421
*.excalidraw
422422
archive/
423-
test/.CondaPkg/
423+
**/*/.CondaPkg/
424424
.CondaPkg/
425425
CondaPkg.toml

test/Project.toml

-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ BlockArrays = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
55
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
66
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
77
ChainRulesTestUtils = "cdddcdb0-9152-4a09-a978-84456f9df70a"
8-
CondaPkg = "992eb4ea-22a4-4c89-a5bb-47a3300528ab"
98
Dagger = "d58978e5-989f-55fb-8d15-ea34adc7bf54"
109
DeltaArrays = "10b0fc19-5ccc-4427-889b-d75dd6306188"
1110
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
@@ -19,17 +18,13 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1918
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
2019
NetworkLayout = "46757867-2c16-5918-afeb-47bfcb05e46a"
2120
OMEinsum = "ebe7aa44-baf0-506c-a96f-8464559b3922"
22-
Permutations = "2ae35dd2-176d-5d53-8349-f30d82d94d4f"
23-
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
24-
PythonCall = "6099a3de-0909-46bc-b1f4-468b9a2dfc0d"
2521
Quac = "b9105292-1415-45cf-bff1-d6ccf71e6143"
2622
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
2723
Reactant = "3c362404-f566-11ee-1572-e11a4b42c853"
2824
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
2925
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
3026
Tenet = "85d41934-b9cd-44e1-8730-56d86f15f3ec"
3127
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
32-
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
3328
Yao = "5872b779-8223-5990-8dd0-5abbb0748c8c"
3429
YaoBlocks = "418bc28f-b43b-5e0b-a6e7-61bbc1a2c1df"
3530

test/integration/python/test_cirq.jl

-53
This file was deleted.

test/integration/python/test_qibo.jl

-22
This file was deleted.

test/integration/python/test_qiskit.jl

-22
This file was deleted.

test/integration/python/test_quimb.jl

-18
This file was deleted.

test/python/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!CondaPkg.toml
File renamed without changes.

test/python/Project.toml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[deps]
2+
CondaPkg = "992eb4ea-22a4-4c89-a5bb-47a3300528ab"
3+
PythonCall = "6099a3de-0909-46bc-b1f4-468b9a2dfc0d"
4+
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
5+
Tenet = "85d41934-b9cd-44e1-8730-56d86f15f3ec"
6+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
7+
8+
[sources]
9+
Tenet = {path = "../.."}

test/python/runtests.jl

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using Test
2+
using Tenet
3+
using SafeTestsets
4+
5+
# add python test dependencies
6+
run(`cp $(joinpath(@__DIR__, "CondaPkg.toml")) $(joinpath(@__DIR__, "..", "..", "CondaPkg.toml"))`)
7+
using CondaPkg
8+
CondaPkg.update()
9+
using PythonCall
10+
11+
@testset "Python" verbose = true begin
12+
@safetestset "Cirq" begin
13+
include("test_cirq.jl")
14+
end
15+
16+
@safetestset "Quimb" begin
17+
include("test_quimb.jl")
18+
end
19+
20+
@safetestset "Qiskit" begin
21+
include("test_qiskit.jl")
22+
end
23+
24+
@safetestset "Qibo" begin
25+
include("test_qibo.jl")
26+
end
27+
end
28+
29+
# cleaning
30+
run(`rm $(joinpath(@__DIR__, "..", "..", "CondaPkg.toml"))`)

test/python/test_cirq.jl

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using Test
2+
using Tenet
3+
using PythonCall
4+
cirq = pyimport("cirq")
5+
6+
@testset "LineQubit" begin
7+
circuit = cirq.Circuit()
8+
qubits = cirq.LineQubit.range(3)
9+
circuit.append(cirq.H(qubits[0]))
10+
circuit.append(cirq.H(qubits[1]))
11+
circuit.append(cirq.CNOT(qubits[1], qubits[2]))
12+
circuit.append(cirq.CNOT(qubits[0], qubits[2]))
13+
circuit.append(cirq.H(qubits[0]))
14+
circuit.append(cirq.H(qubits[1]))
15+
circuit.append(cirq.H(qubits[2]))
16+
17+
circ = convert(Circuit, circuit)
18+
@test issetequal(sites(circ; set=:inputs), Site.([0, 1, 2]; dual=true))
19+
@test issetequal(sites(circ; set=:outputs), Site.([0, 1, 2]))
20+
@test Tenet.ntensors(circ) == 7
21+
@test issetequal(
22+
moments(circ),
23+
[Tenet.Moment.(Ref(Lane(0)), 1:4)..., Tenet.Moment.(Ref(Lane(1)), 1:4)..., Tenet.Moment.(Ref(Lane(2)), 1:4)...],
24+
)
25+
end
26+
27+
@testset "GridQubit" begin
28+
circuit = cirq.Circuit()
29+
qubits = cirq.GridQubit.rect(3, 1)
30+
circuit.append(cirq.H(qubits[0]))
31+
circuit.append(cirq.H(qubits[1]))
32+
circuit.append(cirq.CNOT(qubits[1], qubits[2]))
33+
circuit.append(cirq.CNOT(qubits[0], qubits[2]))
34+
circuit.append(cirq.H(qubits[0]))
35+
circuit.append(cirq.H(qubits[1]))
36+
circuit.append(cirq.H(qubits[2]))
37+
38+
circ = convert(Circuit, circuit)
39+
@test issetequal(sites(circ; set=:inputs), Site.([(0, 0), (1, 0), (2, 0)]; dual=true))
40+
@test issetequal(sites(circ; set=:outputs), Site.([(0, 0), (1, 0), (2, 0)]))
41+
@test Tenet.ntensors(circ) == 7
42+
@test issetequal(
43+
moments(circ),
44+
[
45+
Tenet.Moment.(Ref(Lane(0, 0)), 1:4)...,
46+
Tenet.Moment.(Ref(Lane(1, 0)), 1:4)...,
47+
Tenet.Moment.(Ref(Lane(2, 0)), 1:4)...,
48+
],
49+
)
50+
end

test/python/test_qibo.jl

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using Test
2+
using Tenet
3+
using PythonCall
4+
qibo = pyimport("qibo")
5+
6+
circuit = qibo.Circuit(3)
7+
circuit.add(qibo.gates.H(0))
8+
circuit.add(qibo.gates.H(1))
9+
circuit.add(qibo.gates.CNOT(1, 2))
10+
circuit.add(qibo.gates.CNOT(0, 2))
11+
circuit.add(qibo.gates.H(0))
12+
circuit.add(qibo.gates.H(1))
13+
circuit.add(qibo.gates.H(2))
14+
15+
circ = convert(Circuit, circuit)
16+
@test circ isa Circuit
17+
@test issetequal(sites(circ; set=:inputs), Site.([0, 1, 2]; dual=true))
18+
@test issetequal(sites(circ; set=:outputs), Site.([0, 1, 2]))
19+
@test Tenet.ntensors(circ) == 7
20+
@test issetequal(
21+
moments(circ),
22+
[Tenet.Moment.(Ref(Lane(0)), 1:4)..., Tenet.Moment.(Ref(Lane(1)), 1:4)..., Tenet.Moment.(Ref(Lane(2)), 1:4)...],
23+
)

test/python/test_qiskit.jl

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using Test
2+
using Tenet
3+
using PythonCall
4+
qiskit = pyimport("qiskit")
5+
6+
circuit = qiskit.QuantumCircuit(3)
7+
circuit.h(0)
8+
circuit.h(1)
9+
circuit.cx(1, 2)
10+
circuit.cx(0, 2)
11+
circuit.h(0)
12+
circuit.h(1)
13+
circuit.h(2)
14+
15+
tn = convert(Circuit, circuit)
16+
@test tn isa Circuit
17+
@test issetequal(sites(tn; set=:inputs), Site.([1, 2, 3]; dual=true))
18+
@test issetequal(sites(tn; set=:outputs), Site.([1, 2, 3]))
19+
@test Tenet.ntensors(tn) == 7
20+
@test issetequal(
21+
moments(tn),
22+
[Tenet.Moment.(Ref(Lane(1)), 1:4)..., Tenet.Moment.(Ref(Lane(2)), 1:4)..., Tenet.Moment.(Ref(Lane(3)), 1:4)...],
23+
)

test/python/test_quimb.jl

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Test
2+
using Tenet
3+
using PythonCall
4+
qtn = pyimport("quimb.tensor")
5+
6+
# NOTE quimb.circuit.Circuit splits gates by default
7+
qc = qtn.Circuit(3; gate_opts=Dict(["contract" => false]))
8+
gates = [("H", 0), ("H", 1), ("CNOT", 1, 2), ("CNOT", 0, 2), ("H", 0), ("H", 1), ("H", 2)]
9+
qc.apply_gates(gates)
10+
11+
tn = convert(Quantum, qc)
12+
@test issetequal(sites(tn; set=:inputs), adjoint.(Site.([0, 1, 2])))
13+
@test issetequal(sites(tn; set=:outputs), Site.([0, 1, 2]))
14+
@test Tenet.ntensors(tn) == 7
15+
16+
tn = convert(Quantum, qc.psi)
17+
@test isempty(sites(tn; set=:inputs))
18+
@test issetequal(sites(tn; set=:outputs), Site.([0, 1, 2]))
19+
@test Tenet.ntensors(tn) == 10

0 commit comments

Comments
 (0)