# \~quantum-rt\@1.0 device

### About

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.

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.

{% hint style="warning" %}
***This device is currently simulation-based using roqoqo-quest backend - for educational purposes only***
{% endhint %}

#### What is Quantum Computing?

Quantum computing make use of quantum mechanical phenomena such as superposition and entanglement to process information in fundamentally different ways than classical computers.

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.

### \~quantum-rt\@1.0 device

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.

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.

#### Available Quantum Functions (in simulation mode)

* **superposition**: creates quantum superposition state on a single qubit
* **quantum\_rng**: quantum (pseuo)random number generator using multiple qubits
* **bell\_state**: creates entangled Bell states between qubits
* **quantum\_teleportation**: implements quantum teleportation protocol

### Quantum Runtime Technical Architecture

```rust
#[rustler::nif]
fn hello() -> NifResult<String> {
    Ok("Hello world!".to_string())
}

#[rustler::nif(schedule = "DirtyCpu")]
fn compute(
    num_qubits: usize,
    function_id: String,
    measurements: Vec<usize>,
) -> NifResult<HashMap<String, f64>> {
    let runtime = Runtime::new(num_qubits);
    match runtime.execute_serverless(function_id, measurements) {
        Ok(result) => Ok(result),
        Err(_) => Err(rustler::Error::Term(Box::new("execution failed"))),
    }
}
```

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.

<figure><img src="/files/VgBApnpPLuOltCZX3l9g" alt=""><figcaption><p>execution flow</p></figcaption></figure>

### Device API Examples

**Generate Quantum Random Numbers**

```bash
curl -X POST "https://hb.load.rs/~quantum-rt@1.0/compute" \
  -H "Content-Type: application/json" \
  -d '{
    "function_id": "quantum_rng",
    "num_qubits": 4,
    "measurements": [0, 1, 2, 3]
  }'
```

### References

* hb device interface: [dev\_quantum.erl](https://github.com/loadnetwork/load_hb/blob/main/src/dev_quantum.erl)
* nif interface: [quantum\_runtime\_nif.erl](https://github.com/loadnetwork/load_hb/blob/main/src/quantum_runtime_nif.erl)
* quantum functions registry: [registry.rs](https://github.com/loadnetwork/load_hb/blob/main/native/quantum_runtime_nif/src/core/registry.rs)
* runtime core: [runtime.rs](https://github.com/loadnetwork/load_hb/blob/main/native/quantum_runtime_nif/src/core/runtime.rs)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.load.network/load-hyperbeam/quantum-rt-1.0-device.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
