opencl.rs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. extern crate qcgpu;
  2. use qcgpu::Simulator;
  3. fn create_simulator(n: u8) -> Simulator {
  4. let sim = Simulator::new_opencl(n);
  5. assert!(
  6. sim.is_ok(),
  7. "Error initializing OpenCL simulator"
  8. );
  9. return sim.unwrap();
  10. }
  11. #[test]
  12. fn can_initialize_simulator() {
  13. for n in 1..25 {
  14. create_simulator(n);
  15. }
  16. }
  17. #[test]
  18. fn can_apply_x_gate() {
  19. for n in 1..25 {
  20. let mut sim = create_simulator(n);
  21. for i in 0..n {
  22. assert!(
  23. sim.x(i).is_ok(),
  24. "Error applying pauli-x (not) gate to simulator"
  25. );
  26. }
  27. }
  28. }
  29. #[test]
  30. fn can_apply_y_gate() {
  31. for n in 1..25 {
  32. let mut sim = create_simulator(n);
  33. for i in 0..n {
  34. assert!(
  35. sim.y(i).is_ok(),
  36. "Error applying pauli-y gate to simulator"
  37. );
  38. }
  39. }
  40. }
  41. #[test]
  42. fn can_apply_z_gate() {
  43. for n in 1..25 {
  44. let mut sim = create_simulator(n);
  45. for i in 0..n {
  46. assert!(
  47. sim.z(i).is_ok(),
  48. "Error applying pauli-z gate to simulator"
  49. );
  50. }
  51. }
  52. }
  53. #[test]
  54. fn can_apply_h_gate() {
  55. for n in 1..25 {
  56. let mut sim = create_simulator(n);
  57. for i in 0..n {
  58. assert!(
  59. sim.h(i).is_ok(),
  60. "Error applying hadamard gate to simulator"
  61. );
  62. }
  63. }
  64. }
  65. #[test]
  66. fn can_apply_cx_gate() {
  67. for n in 2..25 {
  68. let mut sim = create_simulator(n);
  69. for i in 1..n {
  70. assert!(
  71. sim.cx(0, i).is_ok(),
  72. "Error applying controlled not gate to simulator"
  73. );
  74. }
  75. }
  76. }