Przeglądaj źródła

Formatting / General Refactor

Adam Kelly 6 lat temu
rodzic
commit
3b05e81cde
6 zmienionych plików z 27 dodań i 12 usunięć
  1. 2 2
      examples/bell-state.rs
  2. 1 1
      src/backends/opencl/mod.rs
  3. 6 6
      src/error.rs
  4. 1 1
      src/lib.rs
  5. 2 2
      src/traits.rs
  6. 15 0
      tests/opencl.rs

+ 2 - 2
examples/bell-state.rs

@@ -13,8 +13,8 @@ fn main() {
 
     let mut sim = Simulator::new_opencl(2).unwrap();
 
-    sim.h(0);
-    sim.cx(0, 1);
+    sim.h(0).unwrap();
+    sim.cx(0, 1).unwrap();
 
     println!("Measurement Results:");
     println!("{}", sim.measure().unwrap());

+ 1 - 1
src/backends/opencl/mod.rs

@@ -150,7 +150,7 @@ impl Backend for OpenCL {
     /// Measure the value of a single qubit, leaving the register in
     /// the state where only that qubit (or any entangled qubits) have
     /// been collapsed
-    fn measure_qubit(&mut self, target: u8) -> Result<u8, Error> {
+    fn measure_qubit(&mut self, _target: u8) -> Result<u8, Error> {
         unimplemented!()
     }
 

+ 6 - 6
src/error.rs

@@ -28,11 +28,11 @@ impl fmt::Display for BackendError {
     }
 }
 
-impl BackendError {
-    pub fn kind(&self) -> BackendErrorKind {
-        *self.inner.get_context()
-    }
-}
+// impl BackendError {
+//     pub fn kind(&self) -> BackendErrorKind {
+//         *self.inner.get_context()
+//     }
+// }
 
 impl From<BackendErrorKind> for BackendError {
     fn from(kind: BackendErrorKind) -> BackendError {
@@ -44,6 +44,6 @@ impl From<BackendErrorKind> for BackendError {
 
 impl From<Context<BackendErrorKind>> for BackendError {
     fn from(inner: Context<BackendErrorKind>) -> BackendError {
-        BackendError { inner: inner }
+        BackendError { inner }
     }
 }

+ 1 - 1
src/lib.rs

@@ -12,7 +12,7 @@ pub mod traits;
 pub mod backends;
 
 use backends::OpenCL;
-use gate::{h, x, y, z, Gate};
+pub use gate::{h, x, y, z, Gate};
 
 use std::fmt;
 use failure::Error;

+ 2 - 2
src/traits.rs

@@ -14,10 +14,10 @@ pub trait Backend: Debug + Display {
             let bit_mask = 1 << i;
             if self.measure_qubit(i)? == 1 {
                 // 1, set the bit in result
-                result = result | bit_mask
+                result |= bit_mask
             } else {
                 // 0, clear the bit in result
-                result = result & (!bit_mask)
+                result &= !bit_mask
             }
         }
 

+ 15 - 0
tests/opencl.rs

@@ -0,0 +1,15 @@
+extern crate qcgpu;
+
+use qcgpu::Simulator;
+
+#[test]
+fn can_initialize_simulator() {
+    for n in 1..25 {
+        let sim = Simulator::new_opencl(n);
+
+        assert!(
+            sim.is_ok(),
+            "Error initializing OpenCL simulator"
+        );
+    }
+}