|
| 1 | +## About |
| 2 | + |
| 3 | +The `quantum_runtime_nif` is the foundation of the `~quantum-rt@1.0` device: a quantum computing runtime built on top of roqoqo simulation framework. This hyperbeam device enables serverless quantum function execution, positioning hyperbeam nodes running this device as providers of serverless functions compute. |
| 4 | + |
| 5 | +The device supports quantum circuit execution, measurement-based quantum computation, and provides a registry of pre-built quantum functions including superposition states, quantum random number generation, and quantum teleportation protocols. |
| 6 | + |
| 7 | +***[!] This device is currently simulation-based using roqoqo-quest backend - for educational purposes only [!]*** |
| 8 | + |
| 9 | +### What is Quantum Computing? |
| 10 | + |
| 11 | +Quantum computing make use of quantum mechanical phenomena such as superposition and entanglement to process information in fundamentally different ways than classical computers. |
| 12 | + |
| 13 | +Unlike classical bits that exist in definite states (0 or 1), quantum bits (qubits) can exist in superposition of both states simultaneously, enabling parallel computation across multiple possibilities. |
| 14 | + |
| 15 | +## ~quantum-rt@1.0 device |
| 16 | + |
| 17 | +The `~quantum-rt@1.0` device, as per its current implementation, provides a serverless quantum function execution environment. It uses the roqoqo simulation backend for development and testing, but can be adapted to real quantum computation using services like [AQT.eu](https://aqt.eu) or other quantum cloud providers such as IBM Quantum Platform, with minimal device code changes. |
| 18 | + |
| 19 | +The device supports quantum circuits with up to 32 qubits and provides a registry of whitelisted quantum functions that can be executed through HTTP calls or via ao messaging. |
| 20 | + |
| 21 | +### Available Quantum Functions (in simulation mode) |
| 22 | + |
| 23 | +- **superposition**: creates quantum superposition state on a single qubit |
| 24 | +- **quantum_rng**: quantum (pseuo)random number generator using multiple qubits |
| 25 | +- **bell_state**: creates entangled Bell states between qubits |
| 26 | +- **quantum_teleportation**: implements quantum teleportation protocol |
| 27 | + |
| 28 | +## Quantum Runtime Technical Architecture |
| 29 | + |
| 30 | +```rust |
| 31 | +#[rustler::nif] |
| 32 | +fn hello() -> NifResult<String> { |
| 33 | + Ok("Hello world!".to_string()) |
| 34 | +} |
| 35 | + |
| 36 | +#[rustler::nif(schedule = "DirtyCpu")] |
| 37 | +fn compute( |
| 38 | + num_qubits: usize, |
| 39 | + function_id: String, |
| 40 | + measurements: Vec<usize>, |
| 41 | +) -> NifResult<HashMap<String, f64>> { |
| 42 | + let runtime = Runtime::new(num_qubits); |
| 43 | + match runtime.execute_serverless(function_id, measurements) { |
| 44 | + Ok(result) => Ok(result), |
| 45 | + Err(_) => Err(rustler::Error::Term(Box::new("execution failed"))), |
| 46 | + } |
| 47 | +} |
| 48 | +``` |
| 49 | + |
| 50 | +The compute() function takes 3 inputs: the number of qubits to initialize, a function ID from the serverless registry, and a list of qubit indices to measure. It returns a HashMap containing the measurement results. |
| 51 | + |
| 52 | +```mermaid |
| 53 | +graph TD |
| 54 | + Qubits[Number of Qubits] --> Runtime[Runtime::new] |
| 55 | + FuncID[Function ID] --> Registry[Function Registry] |
| 56 | + Measurements[Measurement Indices] --> Runtime |
| 57 | + |
| 58 | + Runtime --> Backend[roqoqo-quest Backend] |
| 59 | + Registry --> Circuit[Quantum Circuit] |
| 60 | + Circuit --> Backend |
| 61 | + |
| 62 | + Backend --> Simulate[Quantum Simulation] |
| 63 | + Simulate --> Measure[Measure Qubits] |
| 64 | + Measure --> Results[HashMap Results] |
| 65 | + |
| 66 | + Results --> NIF[Return to dev_quantum.erl] |
| 67 | + |
| 68 | + style Backend fill:#e1f5fe |
| 69 | + style Simulate fill:#f3e5f5 |
| 70 | + style Results fill:#e8f5e8 |
| 71 | +``` |
| 72 | + |
| 73 | +## Device API Examples |
| 74 | + |
| 75 | +#### Generate Quantum Random Numbers |
| 76 | + |
| 77 | +```bash |
| 78 | +curl -X POST "https://hb.load.rs/~quantum-rt@1.0/compute" \ |
| 79 | + -H "Content-Type: application/json" \ |
| 80 | + -d '{ |
| 81 | + "function_id": "quantum_rng", |
| 82 | + "num_qubits": 4, |
| 83 | + "measurements": [0, 1, 2, 3] |
| 84 | + }' |
| 85 | +``` |
| 86 | + |
| 87 | +## References |
| 88 | + |
| 89 | +- hb device interface: [dev_quantum.erl](../../src/dev_quantum.erl) |
| 90 | +- nif interface: [quantum_runtime_nif.erl](../../src/quantum_runtime_nif.erl) |
| 91 | +- quantum functions registry: [registry.rs](./src/core/registry.rs) |
| 92 | +- runtime core: [runtime.rs](./src/core/runtime.rs) |
| 93 | + |
| 94 | +## License |
| 95 | +This device is licensed under the [MIT License](./LICENSE) |
0 commit comments