diff options
| author | hachem <im@hachem.wtf> | 2024-09-26 21:40:04 +0200 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2024-09-26 21:40:04 +0200 |
| commit | 1070a7ee073471af8442826cec54e720be266c7c (patch) | |
| tree | 8118c244731fa28409b70cedd69f8c6c057f4b33 | |
| parent | d65b1c55782f6a9d89cd5bc7c7337397dcf4b85c (diff) | |
Runtime architecture start
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | libpsi-core/src/core/circuit.rs | 12 | ||||
| -rw-r--r-- | libpsi-core/src/core/mod.rs | 2 | ||||
| -rw-r--r-- | libpsi-core/src/core/runtime.rs | 25 | ||||
| -rw-r--r-- | libpsi-core/src/lib.rs | 4 | ||||
| -rw-r--r-- | libpsi-core/src/runtimes/basic_rt.rs | 26 | ||||
| -rw-r--r-- | libpsi-core/src/runtimes/mod.rs | 3 | ||||
| -rw-r--r-- | libpsi-tester/src/main.rs | 6 |
8 files changed, 76 insertions, 4 deletions
@@ -12,7 +12,7 @@ $\psi$ is a powerful quantum computing toolkit designed for simulating quantum c - **`libpsi-core:maths`**: A comprehensive mathematics library featuring 32/64-bit complex numbers, vectors (both row and column), matrices, and more. - **`libpsi-core:core`**: Contains all core quantum components, including quantum gates, classical/quantum bits, and quantum circuits. - **`libpsi-visualizer`**: An extension of `libpsi-core` that offers visual representations of quantum circuits. It supports both text-based (ASCII) output in the terminal and graphical output using APIs like OpenGL and Vulkan. -- **`qasmc`**: An [OpenQASM](https://openqasm.com/) compiler that enables you to write quantum programs, which are then compiled into native executables for classical computers using an [LLVM](https://llvm.org/) backend. +- **`libpsi-qasmc`**: An [OpenQASM](https://openqasm.com/) compiler that enables you to write quantum programs, which are then compiled into native executables for classical computers using an [LLVM](https://llvm.org/) backend. - **`psi`**: A C-like programming language that integrates quantum and classical computing, making it easier to build and simulate quantum systems alongside classical ones. - **`psi-gui`**: A graphical interface for designing quantum circuits, allowing you to create circuits visually rather than through code. It integrates `libpsi` and `psi`. diff --git a/libpsi-core/src/core/circuit.rs b/libpsi-core/src/core/circuit.rs index 65e359a..43f51d0 100644 --- a/libpsi-core/src/core/circuit.rs +++ b/libpsi-core/src/core/circuit.rs @@ -2,8 +2,8 @@ use super::{ClassicalRegister, QuantumBit, QuantumGate}; #[allow(dead_code)] struct QuantumCircuitInstruction { - target_indices: Vec<i32>, - control_indices: Vec<i32>, + target_indices: Vec<usize>, + control_indices: Vec<usize>, gate: QuantumGate, } @@ -22,4 +22,12 @@ impl QuantumCircuit { instructions: Vec::new(), } } + + pub fn apply(&mut self, gate: &QuantumGate, control_bits: &[usize], target_bits: &[usize]) { + self.instructions.push(QuantumCircuitInstruction { + gate: gate.clone(), + target_indices: target_bits.to_vec(), + control_indices: control_bits.to_vec(), + }); + } } diff --git a/libpsi-core/src/core/mod.rs b/libpsi-core/src/core/mod.rs index 2f42682..e8e2a4b 100644 --- a/libpsi-core/src/core/mod.rs +++ b/libpsi-core/src/core/mod.rs @@ -1,7 +1,9 @@ pub mod circuit; pub mod component; pub mod gates; +pub mod runtime; pub use circuit::*; pub use component::*; pub use gates::*; +pub use runtime::*; diff --git a/libpsi-core/src/core/runtime.rs b/libpsi-core/src/core/runtime.rs new file mode 100644 index 0000000..f699d54 --- /dev/null +++ b/libpsi-core/src/core/runtime.rs @@ -0,0 +1,25 @@ +use super::{ClassicalRegister, QuantumBit, QuantumCircuit}; + +#[allow(unused)] +pub struct ExecutationData { + quantum_states: Vec<QuantumBit>, + classical_states: ClassicalRegister, +} + +impl ExecutationData { + pub fn new(quantum_states: Vec<QuantumBit>, classical_states: ClassicalRegister) -> Self { + ExecutationData { + quantum_states, + classical_states, + } + } +} + +pub trait RuntimeBase { + fn get_circuit(&self) -> &QuantumCircuit; +} + +pub trait Runtime<T: RuntimeBase = Self> { + fn new(circuit: QuantumCircuit) -> Self; + fn execute(&self, repeat: usize) -> Vec<ExecutationData>; +} diff --git a/libpsi-core/src/lib.rs b/libpsi-core/src/lib.rs index 45c2c3b..0be80cc 100644 --- a/libpsi-core/src/lib.rs +++ b/libpsi-core/src/lib.rs @@ -1,5 +1,6 @@ pub mod core; pub mod maths; +pub mod runtimes; pub use maths::complex::*; pub use maths::matrix::*; @@ -9,3 +10,6 @@ pub use maths::vector::*; pub use core::circuit::*; pub use core::component::*; pub use core::gates; +pub use core::runtime::*; + +pub use runtimes::*; diff --git a/libpsi-core/src/runtimes/basic_rt.rs b/libpsi-core/src/runtimes/basic_rt.rs new file mode 100644 index 0000000..78d6122 --- /dev/null +++ b/libpsi-core/src/runtimes/basic_rt.rs @@ -0,0 +1,26 @@ +use crate::{ClassicalRegister, ExecutationData, QuantumCircuit, Runtime, RuntimeBase}; + +pub struct BasicRT { + circuit: QuantumCircuit, +} + +impl RuntimeBase for BasicRT { + fn get_circuit(&self) -> &QuantumCircuit { + &self.circuit + } +} + +impl Runtime for BasicRT { + fn new(circuit: QuantumCircuit) -> BasicRT { + BasicRT { circuit } + } + + fn execute(&self, repeat: usize) -> Vec<ExecutationData> { + let mut result: Vec<ExecutationData> = Vec::with_capacity(repeat); + for _ in 0..repeat { + let executation_data = ExecutationData::new(Vec::new(), ClassicalRegister::new(1)); + result.push(executation_data); + } + result + } +} diff --git a/libpsi-core/src/runtimes/mod.rs b/libpsi-core/src/runtimes/mod.rs new file mode 100644 index 0000000..4c2030c --- /dev/null +++ b/libpsi-core/src/runtimes/mod.rs @@ -0,0 +1,3 @@ +pub mod basic_rt; + +pub use basic_rt::*; diff --git a/libpsi-tester/src/main.rs b/libpsi-tester/src/main.rs index 3fd8de2..2de001b 100644 --- a/libpsi-tester/src/main.rs +++ b/libpsi-tester/src/main.rs @@ -1,5 +1,9 @@ use libpsi_core::*; fn main() { - let _circuit = QuantumCircuit::new(2, 2); + let mut circuit = QuantumCircuit::new(2, 2); + circuit.apply(&gates::CNOT, &[0], &[1]); + + let runtime = BasicRT::new(circuit); + runtime.execute(1024); } |
