123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- extern crate qcgpu;
- use qcgpu::Simulator;
- use qcgpu::gate::x;
- fn create_simulator(n: u8) -> Simulator {
- let sim = Simulator::new_opencl(n);
- assert!(
- sim.is_ok(),
- "Error initializing OpenCL simulator"
- );
- return sim.unwrap();
- }
- #[test]
- fn can_initialize_simulator() {
- for n in 1..25 {
- create_simulator(n);
- }
- }
- #[test]
- fn can_apply_x_gate() {
- for n in 1..25 {
- let mut sim = create_simulator(n);
- for i in 0..n {
- assert!(
- sim.x(i).is_ok(),
- "Error applying pauli-x (not) gate to simulator"
- );
- }
- }
- }
- #[test]
- fn can_apply_y_gate() {
- for n in 1..25 {
- let mut sim = create_simulator(n);
- for i in 0..n {
- assert!(
- sim.y(i).is_ok(),
- "Error applying pauli-y gate to simulator"
- );
- }
- }
- }
- #[test]
- fn can_apply_z_gate() {
- for n in 1..25 {
- let mut sim = create_simulator(n);
- for i in 0..n {
- assert!(
- sim.z(i).is_ok(),
- "Error applying pauli-z gate to simulator"
- );
- }
- }
- }
- #[test]
- fn can_apply_h_gate() {
- for n in 1..25 {
- let mut sim = create_simulator(n);
- for i in 0..n {
- assert!(
- sim.h(i).is_ok(),
- "Error applying hadamard gate to simulator"
- );
- }
- }
- }
- #[test]
- fn can_apply_cx_gate() {
- for n in 2..25 {
- let mut sim = create_simulator(n);
- for i in 1..n {
- assert!(
- sim.cx(0, i).is_ok(),
- "Error applying controlled not gate to simulator"
- );
- }
- }
- }
- #[test]
- fn can_perform_measurement() {
- for n in 1..25 {
- let mut sim = create_simulator(n);
- sim.apply_all(x()).unwrap();
- assert_eq!(sim.measure().unwrap() as i32, 2i32.pow(n as u32) - 1);
- }
- }
|