Skip to content

Commit 90cd7c6

Browse files
committed
same time operatons in qiskit
1 parent 24b6361 commit 90cd7c6

File tree

5 files changed

+111
-23
lines changed

5 files changed

+111
-23
lines changed

src/Qiskit/Result.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
abstract type Result end
2+
3+
struct QiskitResult <: Result
4+
python_interface::Py
5+
function QiskitResult(python_interface::Py)
6+
new(python_interface)
7+
end
8+
end

src/circuit.jl

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,16 +147,26 @@ function isClifford(circuit::Circuit)
147147
return all([isClifford(operation) for operation in circuit.operations])
148148
end
149149

150-
150+
#TODO apply indentitiy operation to all other qubits/maybe with transpile pass.
151151
function qiskitRepresentation(circuit::Circuit)
152152
qc = Qiskit.QuantumCircuit(length(circuit.lattice))
153+
# iterate execution steps
153154
for i in unique(circuit.executionOrder)
155+
# get all operations in the step
154156
operationsInStep = _getOperations(circuit, i)
155-
for j in operationsInStep
156-
ptr = circuit.operationPointers[j]
157-
applyToQiskit!(qc, circuit.operations[ptr], circuit.operationPositions[j]...)
157+
# get depth of the deepest operation in the step
158+
maximumDepth = maximum([depth(circuit.operations[circuit.operationPointers[j]]) for j in operationsInStep])
159+
# iterate depth of the operations
160+
for k in 1:maximumDepth
161+
# iterate operations in the step
162+
for j in operationsInStep
163+
ptr = circuit.operationPointers[j]
164+
# only apply the k-th instruction of the operation, if deep enough
165+
if k <= depth(circuit.operations[ptr])
166+
applyToQiskit!(qc, circuit.operations[ptr], Val(k), circuit.operationPositions[j]...)
167+
end
168+
end
158169
end
159-
qc.barrier()
160170
end
161171
return qc
162172
end
@@ -188,7 +198,7 @@ function runIBMQ(circuit::Circuit, backend::String; verbose::Bool=true)
188198

189199
verbose && println("Job ID: $(job.job_id())")
190200
end
191-
201+
# job.result()[0].data.c.get_counts().items()
192202
function runQiskitSimulate(circuit::Circuit; verbose::Bool=true)
193203
verbose && print("Transpiling circuit to Qiskit...")
194204
qc = qiskitRepresentation(circuit)

src/operations/XX.jl

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,40 @@ end
1111
function isClifford(::XX)
1212
return true
1313
end
14-
function applyToQiskit!(qc::Qiskit.QuantumCircuit, ::XX, position::Vararg{Integer})
15-
qc.reset(position[2] - 1)
16-
qc.h(position[2] - 1)
17-
qc.cx(position[2] - 1, position[1] - 1)
18-
qc.cx(position[2] - 1, position[3] - 1)
19-
qc.measure(position[2] - 1, position[2] - 1)
14+
function depth(::XX)
15+
return 6
2016
end
2117
function connectionGraph(::XX)
2218
# return the connection graph of the operation
2319
return path_graph(3)
2420
end
21+
function applyToQiskit!(qc::Qiskit.QuantumCircuit, ::XX, p1::Integer, p2::Integer, p3::Integer)
22+
qc.reset(p2 - 1)
23+
qc.h(p2 - 1)
24+
qc.cx(p2 - 1, p1 - 1)
25+
qc.cx(p2 - 1, p3 - 1)
26+
qc.h(p2 - 1)
27+
qc.measure(p2 - 1, p2 - 1)
28+
end
29+
30+
function applyToQiskit!(qc::Qiskit.QuantumCircuit, ::XX, step::Integer, p1::Integer, p2::Integer, p3::Integer)
31+
applyToQiskit!(qc, XX(), Val(step), p1, p2, p3)
32+
end
33+
function applyToQiskit!(qc::Qiskit.QuantumCircuit, ::XX, ::Val{1}, ::Integer, p2::Integer, ::Integer)
34+
qc.reset(p2 - 1)
35+
end
36+
function applyToQiskit!(qc::Qiskit.QuantumCircuit, ::XX, ::Val{2}, ::Integer, p2::Integer, ::Integer)
37+
qc.h(p2 - 1)
38+
end
39+
function applyToQiskit!(qc::Qiskit.QuantumCircuit, ::XX, ::Val{3}, p1::Integer, p2::Integer, ::Integer)
40+
qc.cx(p2 - 1, p1 - 1)
41+
end
42+
function applyToQiskit!(qc::Qiskit.QuantumCircuit, ::XX, ::Val{4}, ::Integer, p2::Integer, p3::Integer)
43+
qc.cx(p2 - 1, p3 - 1)
44+
end
45+
function applyToQiskit!(qc::Qiskit.QuantumCircuit, ::XX, ::Val{5}, ::Integer, p2::Integer, ::Integer)
46+
qc.h(p2 - 1)
47+
end
48+
function applyToQiskit!(qc::Qiskit.QuantumCircuit, ::XX, ::Val{6}, ::Integer, p2::Integer, ::Integer)
49+
qc.measure(p2 - 1, p2 - 1)
50+
end

src/operations/YY.jl

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,40 @@ end
1111
function isClifford(::YY)
1212
return true
1313
end
14-
function applyToQiskit!(qc::Qiskit.QuantumCircuit, ::YY, position::Vararg{Integer})
15-
qc.reset(position[2] - 1)
16-
qc.sdg(position[2] - 1)
17-
qc.cx(position[2] - 1, position[1] - 1)
18-
qc.cx(position[2] - 1, position[3] - 1)
19-
qc.measure(position[2] - 1, position[2] - 1)
14+
function depth(::YY)
15+
return 6
2016
end
2117
function connectionGraph(::YY)
2218
# return the connection graph of the operation
2319
return path_graph(3)
2420
end
21+
function applyToQiskit!(qc::Qiskit.QuantumCircuit, ::YY, p1::Integer, p2::Integer, p3::Integer)
22+
qc.reset(p2 - 1)
23+
qc.sdg(p2 - 1)
24+
qc.cx(p2 - 1, p1 - 1)
25+
qc.cx(p2 - 1, p3 - 1)
26+
qc.h(p2 - 1)
27+
qc.measure(p2 - 1, p2 - 1)
28+
end
29+
30+
function applyToQiskit!(qc::Qiskit.QuantumCircuit, ::YY, step::Integer, p1::Integer, p2::Integer, p3::Integer)
31+
applyToQiskit!(qc, YY(), Val(step), p1, p2, p3)
32+
end
33+
function applyToQiskit!(qc::Qiskit.QuantumCircuit, ::YY, ::Val{1}, ::Integer, p2::Integer, ::Integer)
34+
qc.reset(p2 - 1)
35+
end
36+
function applyToQiskit!(qc::Qiskit.QuantumCircuit, ::YY, ::Val{2}, ::Integer, p2::Integer, ::Integer)
37+
qc.sdg(p2 - 1)
38+
end
39+
function applyToQiskit!(qc::Qiskit.QuantumCircuit, ::YY, ::Val{3}, p1::Integer, p2::Integer, ::Integer)
40+
qc.cx(p2 - 1, p1 - 1)
41+
end
42+
function applyToQiskit!(qc::Qiskit.QuantumCircuit, ::YY, ::Val{4}, ::Integer, p2::Integer, p3::Integer)
43+
qc.cx(p2 - 1, p3 - 1)
44+
end
45+
function applyToQiskit!(qc::Qiskit.QuantumCircuit, ::YY, ::Val{5}, ::Integer, p2::Integer, ::Integer)
46+
qc.h(p2 - 1)
47+
end
48+
function applyToQiskit!(qc::Qiskit.QuantumCircuit, ::YY, ::Val{6}, ::Integer, p2::Integer, ::Integer)
49+
qc.measure(p2 - 1, p2 - 1)
50+
end

src/operations/ZZ.jl

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,31 @@ end
1111
function isClifford(::ZZ)
1212
return true
1313
end
14-
function applyToQiskit!(qc::Qiskit.QuantumCircuit, ::ZZ, position::Vararg{Integer})
15-
qc.reset(position[2] - 1)
16-
qc.cx(position[1] - 1, position[2] - 1)
17-
qc.cx(position[3] - 1, position[2] - 1)
18-
qc.measure(position[2] - 1, position[2] - 1)
14+
function depth(::ZZ)
15+
return 4
1916
end
2017
function connectionGraph(::ZZ)
2118
# return the connection graph of the operation
2219
return path_graph(3)
2320
end
21+
function applyToQiskit!(qc::Qiskit.QuantumCircuit, ::ZZ, p1::Integer, p2::Integer, p3::Integer)
22+
qc.reset(p2 - 1)
23+
qc.cx(p1 - 1, p2 - 1)
24+
qc.cx(p3 - 1, p2 - 1)
25+
qc.measure(p2 - 1, p2 - 1)
26+
end
27+
function applyToQiskit!(qc::Qiskit.QuantumCircuit, ::ZZ, step::Integer, p1::Integer, p2::Integer, p3::Integer)
28+
applyToQiskit!(qc, ZZ(), Val(step), p1, p2, p3)
29+
end
30+
function applyToQiskit!(qc::Qiskit.QuantumCircuit, ::ZZ, ::Val{1}, ::Integer, p2::Integer, ::Integer)
31+
qc.reset(p2 - 1)
32+
end
33+
function applyToQiskit!(qc::Qiskit.QuantumCircuit, ::ZZ, ::Val{2}, p1::Integer, p2::Integer, ::Integer)
34+
qc.cx(p1 - 1, p2 - 1)
35+
end
36+
function applyToQiskit!(qc::Qiskit.QuantumCircuit, ::ZZ, ::Val{3}, ::Integer, p2::Integer, p3::Integer)
37+
qc.cx(p3 - 1, p2 - 1)
38+
end
39+
function applyToQiskit!(qc::Qiskit.QuantumCircuit, ::ZZ, ::Val{4}, ::Integer, p2::Integer, ::Integer)
40+
qc.measure(p2 - 1, p2 - 1)
41+
end

0 commit comments

Comments
 (0)