# TFHE End-to-End Demo (Sunscreen + Lattica)

### What you will do

➤ Create and compile a simple TFHE program that compares two encrypted values

➤ Create a Lattica account and get access.

➤ Set up your account.

➤ Install the management client and deploy the compiled program.

➤ Install the Query Client and run an encrypted query.

➤ Clean up resources.

***

### Part 1: Sunscreen (local)

#### 1. Create and compile a TFHE program

Follow [Sunscreen’s guide](https://github.com/Sunscreen-tech/spf-runner/tree/main/example) to write and compile "greater than" program

**Output of this step:** A compiled TFHE program artifact (ELF)

***

### Part 2: Lattica Console (Web)

#### 2. Create a Lattica account

👉 [Sign up](https://console.lattica.ai/?partner=sunscreen\&signup=true)

***

#### 3. Get license and buy credits

Sign in to the [Console](https://console.lattica.ai/?partner=sunscreen)

In the Console, do both:

**a. Get license**

* Go to Account / License
* Copy your license

<div align="left"><figure><img src="/files/vn6rtr5y2ZkqmK1baso1" alt="" width="375"><figcaption></figcaption></figure></div>

***

### Part 3: Deployment & Access Management (CLI Example)

{% hint style="info" %}
**Alternative: Use the Console**

Instead of using the Management Client commands below, you can:

* [Deploy](/how-to-guides/workload-lifecycle/how-to-deploy-workload.md) the compiled program via the **Lattica Console**
* [Create access tokens](/how-to-guides/access-control/how-to-create-user-access-token.md) via the **Access Management screen**
* Manage [credits ](/how-to-guides/account-and-finance-operations/how-to-view-credit-balance-and-add-credit-to-your-account.md)and [start](/how-to-guides/resource-management/how-to-start-worker.md)/[stop ](/how-to-guides/resource-management/how-to-stop-worker.md)workers from the UI

This demo uses CLI commands for reproducibility and automation.
{% endhint %}

#### 4. Install Management Client

```
pip install lattica-management
```

***

#### 5. Deploy program and start worker

Upload the compiled program from Part 1 and start a worker.

```py
from lattica_management.lattica_management import LatticaManagement
from lattica_common.definitions import InstanceType


LICENSE_KEY = "<YOUR_LICENSE_KEY>"
mgmt_client = LatticaManagement(LICENSE_KEY)

PROGRAM_NAME = "my_greater_than_program"
model_id = mgmt_client.create_model(PROGRAM_NAME, InstanceType.CPU_C7G_XLARGE)

program_params = {
    "compilation_name": "greater_than"
}

PROGRAM_FILE_PATH = "greater_than"
mgmt_client.upload_model_file(PROGRAM_FILE_PATH, model_id, program_params)

worker = mgmt_client.start_worker(model_id, verbose=True)

query_token = mgmt_client.generate_query_token(model_id, token_name="my_greater_than_token1")
```

***

### Part 4: Code – Query

#### 6. Install Query Client

```
pip install lattica-query-sunscreen
```

***

#### 7. Run encrypted query

```python
from lattica_query import client_factory


query_client = client_factory.create_query_client(query_token)
_, keys, _ = query_client.generate_key()

pt = [5, 6]
print(f"Running query with {pt=}...")

result = query_client.run_query(
                keys,
                pt,
                input_types=["u8", "u8"],
                return_type="u8"
            )

print(f"Decrypted Result: {result}")
```

***

### Part 5: Clean up

```py
mgmt_client.stop_worker(model_id, worker['workerSessionId'])
```

***

**Done.**


---

# 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://platformdocs.lattica.ai/demo-tutorials/tfhe-end-to-end-demo-sunscreen-+-lattica.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.
