#gate #zero #qulacs #ry-gate

qurs

Qulacs implementation in Rust

3 unstable releases

0.2.0 Oct 26, 2022
0.1.1 Aug 7, 2022
0.1.0 Oct 30, 2021

#10 in #gate

Download history 6/week @ 2024-02-16 76/week @ 2024-02-23 29/week @ 2024-03-01

111 downloads per month

MIT license

1MB
25K SLoC

C++ 13K SLoC // 0.1% comments C 7.5K SLoC // 0.2% comments CUDA 3K SLoC // 0.1% comments Rust 797 SLoC // 0.0% comments Python 785 SLoC JavaScript 223 SLoC // 0.0% comments Shell 53 SLoC // 0.1% comments Batch 40 SLoC

Qurs

Qurs is an implementation of Qulacs written in Rust. Qurs currently supports only a single processor and depends only on Qulacs C code (qulacs/src/csim).

Qulacs: https://github.com/qulacs

Qurs is licensed under the MIT license.

Build

Qurs uses cc and bindgen to build Qulacs code. The requirements for bindgen are listed in https://rust-lang.github.io/rust-bindgen/requirements.html

cargo build

Example

use num::{Complex, Zero};
use qurs::gate::{ry_gate, x_gate};
use qurs::prelude::*;
use qurs::{self, StateVec};
use std::f64::consts::PI;

fn main() {
	const N: usize = 5;

	//With array
	let mut state = [Complex::zero(); 2usize.pow(N as u32)];
	assert_eq!(state.qubit_count(), N);
	// initialize to |00000>
	state.set_zero_state();
	// initialize to |00101>
	state.set_computational_basis(0b00101);
	// initialize with a random quantum state
	state.set_haar_random_state();
	// Apply x_gate for state
	x_gate(0, &mut state);
	// Rotate PI/2 with respect to Y
	let angle = PI / 2.0;
	ry_gate(0, angle, &mut state);

	//With StateVec
	let mut state = StateVec::new(N);
	assert_eq!(state.qubit_count(), N);
	state.set_zero_state();
	state.set_computational_basis(0b00101);
	state.set_haar_random_state();
	x_gate(0, state.as_mut());
	ry_gate(0, angle, state.as_mut());
}

Dependencies

~0.8–3MB
~56K SLoC