Skip to content

Commit

Permalink
Release spinoza v0.3.0 and spynoza v0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
smu160 committed Dec 4, 2023
1 parent c03583f commit 6bc1487
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 60 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## 0.3.0

- Add example for sampling
- Parallelize sampling and add sampling tests
- `to_table()` now returns a `String` in lieu of just printing the table
- Provide improved examples for python interface users
- Update dependencies to latest available releases
Expand Down
2 changes: 1 addition & 1 deletion spinoza/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "spinoza"
version = "0.2.0"
version = "0.3.0"
edition = "2021"

authors = ["Saveliy Yusufov", "Charlee Stefanski", "Constantin Gonciulea"]
Expand Down
67 changes: 31 additions & 36 deletions spinoza/src/gates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -860,17 +860,16 @@ fn ry_c_apply_strategy3(state: &mut State, control: usize, target: usize, angle:
let s1 = x + (1 << marks.0) + ((x >> marks.0) << marks.0);
let s0 = s1 - dist;

let (a, b, c, d) =
unsafe {
// a + ib
let a = *state_re.get().add(s0);
let b = *state_im.get().add(s0);

// c + id
let c = *state_re.get().add(s1);
let d = *state_im.get().add(s1);
(a, b, c, d)
};
let (a, b, c, d) = unsafe {
// a + ib
let a = *state_re.get().add(s0);
let b = *state_im.get().add(s0);

// c + id
let c = *state_re.get().add(s1);
let d = *state_im.get().add(s1);
(a, b, c, d)
};

unsafe {
*state_re.get().add(s0) = a * cos - c * sin;
Expand All @@ -885,17 +884,16 @@ fn ry_c_apply_strategy3(state: &mut State, control: usize, target: usize, angle:
let s1 = x + (1 << marks.0) + ((x >> marks.0) << marks.0);
let s0 = s1 - dist;

let (a, b, c, d) =
unsafe {
// a + ib
let a = *state_re.get().add(s0);
let b = *state_im.get().add(s0);
let (a, b, c, d) = unsafe {
// a + ib
let a = *state_re.get().add(s0);
let b = *state_im.get().add(s0);

// c + id
let c = *state_re.get().add(s1);
let d = *state_im.get().add(s1);
(a, b, c, d)
};
// c + id
let c = *state_re.get().add(s1);
let d = *state_im.get().add(s1);
(a, b, c, d)
};

unsafe {
*state_re.get().add(s0) = a * cos - c * sin;
Expand Down Expand Up @@ -972,21 +970,18 @@ fn u_apply(state: &mut State, target: usize, theta: Float, phi: Float, lambda: F
let (sp, cp) = Float::sin_cos(phi);

let c = Amplitude { re: ct, im: 0.0 };
let ncs =
Amplitude {
re: -cl * st,
im: -sl * st,
};
let es =
Amplitude {
re: cp * st,
im: sp * st,
};
let ec =
Amplitude {
re: cpl * ct,
im: spl * ct,
};
let ncs = Amplitude {
re: -cl * st,
im: -sl * st,
};
let es = Amplitude {
re: cp * st,
im: sp * st,
};
let ec = Amplitude {
re: cpl * ct,
im: spl * ct,
};
let g = [c, ncs, es, ec];

// NOTE: chunks == end >> target, where end == state.len() >> 1
Expand Down
41 changes: 23 additions & 18 deletions spinoza/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,17 @@ pub fn to_table(state: &State) -> String {
Cell::new(format!("{} = {}", idx, padded_bin(idx, n))),
Cell::new(format!("{:.5} + i{:.5}", z_re, z_im)),
Cell::new(format!("{:.5}", modulus(z_re, z_im))),
Cell::new(str::repeat(" ", (modulus(z_re, z_im) * 50.0).round() as usize))
.bg(complex_to_rgb(z_re, z_im, false)),
Cell::new(str::repeat(
" ",
(modulus(z_re, z_im) * 50.0).round() as usize,
))
.bg(complex_to_rgb(z_re, z_im, false)),
Cell::new(format!("{:.5}", modulus(z_re, z_im).powi(2))),
Cell::new(str::repeat(" ", (modulus(z_re, z_im).powi(2) * 50.0).round() as usize))
.bg(complex_to_rgb(1.0, 0.0, false)),
Cell::new(str::repeat(
" ",
(modulus(z_re, z_im).powi(2) * 50.0).round() as usize,
))
.bg(complex_to_rgb(1.0, 0.0, false)),
]);
});
table.force_no_tty().enforce_styling().style_text_only();
Expand Down Expand Up @@ -133,20 +139,19 @@ fn hsv_to_rgb(hue: f32, sat: f32, val: f32) -> [u8; 3] {
let q = v * (1.0 - s * f);
let t = v * (1.0 - s * (1.0 - f));

let (r, g, b) =
if i == 0 {
(v, t, p)
} else if i == 1 {
(q, v, p)
} else if i == 2 {
(p, v, t)
} else if i == 3 {
(p, q, v)
} else if i == 4 {
(t, p, v)
} else {
(v, p, q)
};
let (r, g, b) = if i == 0 {
(v, t, p)
} else if i == 1 {
(q, v, p)
} else if i == 2 {
(p, v, t)
} else if i == 3 {
(p, q, v)
} else if i == 4 {
(t, p, v)
} else {
(v, p, q)
};
[
(r * 255.0).round() as u8,
(g * 255.0).round() as u8,
Expand Down
2 changes: 1 addition & 1 deletion spynoza/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "spynoza"
version = "0.1.1"
version = "0.3.0"
edition = "2021"

authors = ["Saveliy Yusufov", "Charlee Stefanski", "Constantin Gonciulea"]
Expand Down
7 changes: 3 additions & 4 deletions spynoza/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,9 @@ impl QuantumCircuit {
}

pub fn get_statevector(&self) -> PyResult<PyState> {
let temp =
PyState {
data: self.qc.state.clone(),
};
let temp = PyState {
data: self.qc.state.clone(),
};
Ok(temp)
}

Expand Down

0 comments on commit 6bc1487

Please sign in to comment.