4 个版本
0.1.4 | 2024年2月29日 |
---|---|
0.1.3 | 2024年2月28日 |
0.1.2 | 2024年2月27日 |
0.1.0 | 2024年2月27日 |
#39 在 模拟 中
每月 118 次下载
67KB
1.5K SLoC
Qit
无矩阵运算的简单量子计算机模拟库。
示例
所有门都可以使用 apply 方法对量子比特进行更改。
使用基本门
use Qit::core::{Applicable, Operator, Qubits};
use Qit::gates::{CX, H, U, X, Z, OperatorVec, PushOps};
// 1-Bit Gate
let h_0 = H::new(0);
// create |0⟩ Qubit
let q_in = Qubits::zeros(1);
let q_out = h_0.apply(q_in);
q_out.print_cmps();
// |0⟩ : +0.707 +0.000i
// |1⟩ : +0.707 +0.000i
// 2-Bit Gate
let cx01 = CX::new(0, 1);
// q_in = |01⟩ Qubit
let q_in = Qubits::from_num(2, 1);
let q_out = cx01.apply(q_in);
q_out.print_cmps();
// |00⟩ : +0.000 +0.000i
// |01⟩ : +0.000 +0.000i
// |10⟩ : +0.000 +0.000i
// |11⟩ : +1.000 +0.000i
// Combine gates into one unitary gate
let x = X::new(0);
let cx01 = CX::new(0, 1);
let z = Z::new(1);
let mut circ = OperatorVec::new();
circ.push_ops(x);
circ.push_ops(cx01);
circ.push_ops(z);
let u = U::new(circ, String::from("example_circ"));
let q_in = Qubits::from_num(2, 0);
let q_out = u.apply(q_in);
q_out.print_cmps();
// |00⟩ : +0.000 +0.000i
// |01⟩ : +0.000 +0.000i
// |10⟩ : -0.000 -0.000i
// |11⟩ : -1.000 -0.000i
使用准备好的电路
电路模块实现了一个函数,该函数给出了使用门模块的结构创建的电路。
use Qit::circuits::wrapping_qsub_const;
use Qit::core::{Applicable, Qubits};
use Qit::gates::U;
let b = vec![0, 1, 2];
let sub_2 = wrapping_qsub_const(&b, 2);
let sub_3 = wrapping_qsub_const(&b, 3);
// combine sub_2 and sub_3
let sub_5 = U::new(
vec![Box::new(sub_2), Box::new(sub_3)],
String::from("sub_5"),
);
// q_in = |111⟩
let q_in = Qubits::from_num(3, 7);
let q_out = sub_5.apply(q_in);
q_out.print_cmps();
// |000⟩ : +0.000 +0.000i
// |001⟩ : +0.000 +0.000i
// |010⟩ : +1.000 +0.000i
// |011⟩ : +0.000 +0.000i
// |100⟩ : +0.000 +0.000i
// |101⟩ : +0.000 +0.000i
// |110⟩ : +0.000 +0.000i
// |111⟩ : +0.000 +0.000i
当前版本:0.1.3
此处提供一些额外信息
许可证:MIT
依赖项
~305KB