400Ping commented on code in PR #852:
URL: https://github.com/apache/mahout/pull/852#discussion_r2704740953


##########
qdp/qdp-core/src/gpu/encodings/angle.rs:
##########
@@ -14,37 +14,231 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-// Angle encoding (placeholder)
-// TODO: Rotation-based encoding via tensor product
+// Angle encoding: map per-qubit angles to product state amplitudes.
 
 use super::QuantumEncoder;
+#[cfg(target_os = "linux")]
+use crate::error::cuda_error_to_string;
 use crate::error::{MahoutError, Result};
 use crate::gpu::memory::GpuStateVector;
 use cudarc::driver::CudaDevice;
 use std::sync::Arc;
 
-/// Angle encoding (not implemented)
-/// TODO: Use sin/cos for rotation-based states
+#[cfg(target_os = "linux")]
+use crate::gpu::memory::map_allocation_error;
+#[cfg(target_os = "linux")]
+use cudarc::driver::DevicePtr;
+#[cfg(target_os = "linux")]
+use std::ffi::c_void;
+
+/// Angle encoding: each qubit uses one rotation angle to form a product state.
 pub struct AngleEncoder;
 
 impl QuantumEncoder for AngleEncoder {
     fn encode(
         &self,
-        _device: &Arc<CudaDevice>,
+        #[cfg(target_os = "linux")] device: &Arc<CudaDevice>,
+        #[cfg(not(target_os = "linux"))] _device: &Arc<CudaDevice>,
         data: &[f64],
         num_qubits: usize,
     ) -> Result<GpuStateVector> {
         self.validate_input(data, num_qubits)?;
-        Err(MahoutError::InvalidInput(
-            "Angle encoding not yet implemented. Use 'amplitude' encoding for 
now.".to_string(),
-        ))
+        let state_len = 1 << num_qubits;
+
+        #[cfg(target_os = "linux")]
+        {
+            let input_bytes = std::mem::size_of_val(data);
+            let angles_gpu = {
+                crate::profile_scope!("GPU::H2D_Angles");
+                device.htod_sync_copy(data).map_err(|e| {
+                    map_allocation_error(input_bytes, "angle input upload", 
Some(num_qubits), e)
+                })?

Review Comment:
   Ok, will do this in a follow-up



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to