This project is a proof-of-concept that demonstrates how a user prompt can be "translated" into a quantum computing task. It uses the Qiskit library to execute a quantum circuit on an IBM Quantum simulator.
This initial version translates two specific prompts:
"create_bell_state": This creates a 2-qubit Bell state, which is a fundamental example of quantum entanglement."generate_random_number": This creates an 8-bit truly random number using quantum measurement.
First, it is recommended to create a virtual environment to keep the dependencies for this project isolated.
python3 -m venv venv
source venv/bin/activateThen, install the required Python packages:
pip install -r requirements.txtTo run circuits on IBM's quantum systems (even simulators), you need an API token.
- Create a free account on the IBM Quantum platform.
- Log in to your account.
- On the main dashboard, you will find your API token listed under the "Qiskit in local environment" section on the right-hand side. It will be a long string of random characters. Click the "Copy token" button to copy it to your clipboard.
Create a file named .env in the root of the quantum-translator directory. This file will hold your API token securely.
Add the following line to your .env file, replacing YOUR_API_TOKEN_HERE with the token you copied from the IBM Quantum website:
IBM_QUANTUM_TOKEN="YOUR_API_TOKEN_HERE"
The .gitignore file is already configured to prevent this file from being committed to version control.
Once your environment is set up, you can run the program from the command line.
Pass the desired prompt as an argument.
- To create a Bell state:
python3 main.py "create_bell_state" - To generate a random number:
python3 main.py "generate_random_number"
The program will execute the quantum circuit on a simulator and print a JSON object with the results.
You should see something similar to the following:
{
"prompt": "create_bell_state",
"backend": "generic_backend_8q",
"shots": 1024,
"results": {
"00": 512,
"11": 512
},
"explanation": "The results are counts of the 2-qubit states. For an ideal Bell state, you'd expect to see roughly 50% '00' and 50% '11', indicating entanglement."
}The results dictionary shows the measurement outcomes. In an ideal Bell state (|Φ+⟩), the two qubits are perfectly correlated. When measured, they will both be 0 or both be 1, with a 50% probability for each outcome. The simulation reflects this by showing approximately half the shots resulting in 00 and half resulting in 11.
You should see something similar to the following (the binary_string and random_number will vary):
{
"prompt": "generate_random_number",
"backend": "generic_backend_8q",
"shots": 1,
"binary_string": "10110111",
"random_number": 183,
"explanation": "A Hadamard gate is applied to each qubit to put it in a superposition. When measured, each qubit collapses to 0 or 1 with equal probability, generating a truly random bit."
}