Skip to content

Commit

Permalink
v1.4.7
Browse files Browse the repository at this point in the history
- add ParStart and ParEnd
- performance optimize
- code restructure
  • Loading branch information
dedztbh committed Oct 14, 2020
1 parent c199f9f commit f6a4912
Show file tree
Hide file tree
Showing 8 changed files with 326 additions and 222 deletions.
29 changes: 17 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,47 +82,52 @@ Tester: Similar to TFinder but also run |00..0> (or custom initial state with -i
AllInit: Similar to TFinder but also run every possible initial states (2^N of them) through circuit and print results.

## Commands
i, j, k are indicies of qubit. (0-indexed, left-to-right)
i, j, k are indices of qubit. (0-indexed, left-to-right)

In the input file, each command should be separated by new line or space.

Commands are case-insensitive.

##### Single-Qubit Gates
- Not i
- Hadamard i
+ You can also use "H" instead of "Hadamard"
- CNot i j
- Swap i j
- CCNot i j k
- CSwap i j k
- Y i
- Z i
- CZ i j
+ Controlled Z gate
- S i
- T i
- TDag i
- SqrtNot i
- SqrtNotDag i
- SqrtSwap i j
+ Not implemented yet
- Rot i deg
+ Rotate qubit counterclockwise by degree, not rad

##### Parallel Mode
You can enclose the above single-qubit gates that can run in parallel between "ParStart" and "ParEnd" commands. This can speed up the simulation a lot. Make sure you are using only above single-qubit gates and no two gates are acting on the same qubit.

##### Multi-Qubit Gates
- CNot i j
- Swap i j
- CZ i j
+ Controlled Z gate
- SqrtSwap i j
+ Not implemented yet
- CCNot i j k
- CSwap i j k

##### Measurement (Only works when using Tester)
- Measure n
+ "Magically" measures all qubit state n times in standard basis and print results
+ Will not change qubit state or circuit matrix
+ Only works when using Tester
+ Not saved in circuit matrix
- MeasAll
+ Measure all qubits in standard basis and print measure result
+ Will cause qubit state to collapse
+ Will make circuit matrix unavailable to print or save
+ Only works when using Tester
- MeasOne i
+ Measure one qubits in standard basis and print measure result
+ Will cause qubit state to collapse
+ Will make circuit matrix unavailable to print or save
+ Only works when using Tester

## Note

Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
id("com.github.johnrengelman.shadow") version "6.0.0"
}
group = "com.dedztbh"
version = "1.4.6"
version = "1.4.7"

val projectRoot = "${group}.kuantum"
val projectRootExclude = "/${projectRoot.replace('.', '/')}"
Expand Down
14 changes: 14 additions & 0 deletions src/main/kotlin/com/dedztbh/kuantum/ejml/matrix/const.kt
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,17 @@ val T: ZMatrixRMaj = CMatrix(
val TDag: ZMatrixRMaj = CMatrix(2, 2).also {
COps.transposeConjugate(T, it)
}

fun map0Ctrl(cmd: String) = when (cmd) {
"NOT" -> NOT
"HADAMARD", "H" -> H
"CNOT" -> NOT
"Y" -> Y
"Z" -> Z
"S" -> S
"T" -> T
"TDAG" -> TDag
"SQRTNOT" -> SQRT_NOT
"SQRTNOTDAG" -> SQRT_NOT_DAG
else -> null
}
19 changes: 9 additions & 10 deletions src/main/kotlin/com/dedztbh/kuantum/ejml/operator/AllInit.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.dedztbh.kuantum.ejml.operator
import com.dedztbh.kuantum.common.Config
import com.dedztbh.kuantum.ejml.matrix.*
import com.lukaskusik.coroutines.transformations.map.mapParallel
import com.lukaskusik.coroutines.transformations.reduce.reduceParallel
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.async

Expand All @@ -17,11 +18,10 @@ class AllInit(config: Config, scope: CoroutineScope) : TFinder(config, scope) {
println("\nFinal states: ")
alls.forEachIndexed { idx, arr ->
println("Init ${allssket[idx]}")
val it = arr.iterator()
var jointState = if (it.next() == 0) KET0 else KET1
it.forEachRemaining { i ->
jointState = jointState kron (if (i == 0) KET0 else KET1)
}
val jointState =
arr.map { if (it == 0) KET0 else KET1 }
.asIterable()
.reduceParallel(sqrtN) { a, b -> a kron b }
(opMatrix * jointState).printFancy2(allssket = allssket)
println()
}
Expand All @@ -34,11 +34,10 @@ class PAllInit(config: Config, scope: CoroutineScope) : PTFinder(config, scope)
println("\nFinal states: ")
alls.mapParallel { arr ->
scope.async {
val it = arr.iterator()
var jointState = if (it.next() == 0) KET0 else KET1
it.forEachRemaining { i ->
jointState = jointState kron (if (i == 0) KET0 else KET1)
}
val jointState =
arr.mapParallel { if (it == 0) KET0 else KET1 }
.asIterable()
.reduceParallel(sqrtN) { a, b -> a kron b }
opMatrix * jointState
}
}.forEachIndexed { i, mat ->
Expand Down
Loading

0 comments on commit f6a4912

Please sign in to comment.