Skip to content

Commit 3ae3155

Browse files
Fix README and Circuit::transpile
1 parent d919339 commit 3ae3155

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ simple-qsim is a simple quantum circuit simulator written in Rust. It simulates
99
- Basic gates (X, H, CNOT, etc.)
1010
- Observable for Pauli operators (I, X, Y, Z)
1111
- Parametric gates for RX, RY, RZ
12+
- Transpiler by Solovay-Kitaev algorithm (Thanks to [sk](https://github.com/cmdawson/sk))
13+
- Currently, single-qubit gates are supported.
1214

1315
## Installation
1416

@@ -49,6 +51,12 @@ You can run examples by:
4951
cargo run --example qcl
5052
```
5153

54+
## Test
55+
56+
```
57+
cargo test
58+
```
59+
5260
## License
5361

5462
This project is licensed under the MIT License.

src/circuit.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ use nalgebra_sparse::{coo::CooMatrix, csr::CsrMatrix};
44
use num_complex::Complex;
55

66
use crate::gates::{
7-
h_matrix, inv_t_matrix, rx_matrix, ry_dence_matrix, ry_matrix, rz_dence_matrix, rz_matrix,
8-
s_matrix, t_matrix, x_matrix, y_matrix, z_matrix,
7+
h_matrix, inv_t_matrix, rx_dence_matrix, rx_matrix, ry_dence_matrix, ry_matrix,
8+
rz_dence_matrix, rz_matrix, s_dence_matrix, s_matrix, t_matrix, x_dence_matrix, x_matrix,
9+
y_dence_matrix, y_matrix, z_dence_matrix, z_matrix,
910
};
1011
use crate::net::{Knot, Net};
1112
use crate::qstate::QState;
@@ -306,7 +307,18 @@ impl Circuit {
306307
let mut new_gates = Vec::new();
307308

308309
for gate in &self.gates {
310+
if !matches!(gate.index, GateIndex::One(_)) {
311+
return Err(anyhow::anyhow!(
312+
"Only single qubit gates are supported for transpilation"
313+
));
314+
}
315+
309316
let u = match &gate.kind {
317+
GateKind::S => s_dence_matrix(),
318+
GateKind::X => x_dence_matrix(),
319+
GateKind::Y => y_dence_matrix(),
320+
GateKind::Z => z_dence_matrix(),
321+
GateKind::RX(angle) => rx_dence_matrix(*angle),
310322
GateKind::RY(angle) => ry_dence_matrix(*angle),
311323
GateKind::RZ(angle) => rz_dence_matrix(*angle),
312324
_ => {

src/gates.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,15 @@ pub fn s_matrix() -> CsrMatrix<Qbit> {
122122
CsrMatrix::from(&s_coo)
123123
}
124124

125+
pub fn s_dence_matrix() -> Matrix2<Qbit> {
126+
Matrix2::from_column_slice(&[
127+
Complex::ONE,
128+
Complex::ZERO,
129+
Complex::ZERO,
130+
Complex::new(0.0, 1.0),
131+
])
132+
}
133+
125134
pub fn t_matrix() -> CsrMatrix<Qbit> {
126135
let mut t_coo = CooMatrix::new(2, 2);
127136
t_coo.push(0, 0, Complex::new(1.0, 0.0));

0 commit comments

Comments
 (0)