Skip to content

Commit

Permalink
cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
rr637 committed Jan 17, 2025
1 parent 99bd40a commit 91f014a
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 23 deletions.
Binary file modified .DS_Store
Binary file not shown.
11 changes: 11 additions & 0 deletions ISA_py/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Python Implementation of ISA

- **`qc.py`**: This file defines the Gate class and how rotations and CX gates are applied to quantum states. Gates are validated by qiskit's statevector simulator.
- **`sp3_extension`**: This file implements 3-qubit state preparation, which is the base case for 2-bit patterns (k=2).
- **`parser.py`**: This file defines function to extract state from properly formatted text file.
- **`util.py`**: This file contains more helpers.
- **`isa.py`**: This file implements the enumeration of patterns and iterative merging step. It combines files in folder to define isa.prepare() which outputs same gate sequence as C++ executable.
- **`py_demo.py`** This script runs isa.prepare() and outputs the ISA gate sequence.



20 changes: 8 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
# README
# QSP-ISA-Protein

## QSP-ISA-Protein
This repository contains the implementations, experiments, and results for our manuscript on **"Encoding Proteins as Quantum States with Approximate Quantum State Preparation by Iterated Sparse State Preparation"**

## Folders

- **/cpp** - C++ Implementations of ISA, ADAPT-VQE, and AA-VQC
- **/Protein_exp** - Protein experiments and QSP scripts
- **/ISA_py** - Python implementation of ISA (Not used for final experimentation)
- **/qiskit_simulations** - Experiments for preparing states using ISA on IBM simulator
- **/data_and_logs** - Results and input/output text files





- [**cpp/**](./cpp) contains C++ implementations of ISA, ADAPT-VQE, and AA-VQC.
- [**Protein_exp/**](./Protein_exp) contains protein experiments and QSP scripts.
- [**ISA_py/**](./ISA_py) contains Python implementation of ISA.
- [**qiskit_simulations/**](./qiskit_simulations) contains exeriments for preparing states using ISA on IBM devices.
- [**data_and_logs**](./data_and_logs) contains results and input/output text files.



Expand Down
27 changes: 27 additions & 0 deletions cpp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# ISA, AA-VQC, and ADAPT-VQE Implementations

## Iterated Sparse Approximation Files
- **`isa_main.cpp/hpp`**: This is the main script for running the ISA algorithm.
- **`simulator.cpp/hpp`**: This file contains functions for simulating the application of quantum gates to quantum states.
- **`state_tracker.cpp/hpp`**: This file is a wrapper around **`simulator.cpp/hpp`** and implements the iterative merging step for ISA.
- **`sp3.cpp/hpp`**: This file implements 3-qubit state preparation, which is the base case for 2-bit patterns (k=2).
- **`greedy.cpp/hpp`**: This file implements ISA for k=1.
- **`greedy3.cpp/hpp`**: This file implements ISA for k=2.
- **`pattern.cpp/hpp`**: This file implements the pattern data structure.

## Alternating Ansatz - Variational Quantum Circuit Files
- **`vqc.cpp/hpp`**: This file implements gradient descent for AA-VQC based on this paper: https://arxiv.org/abs/2011.06258.
- **`vqc_main.cpp/hpp`**: This is the main script for running the AA-VQC algorithm.

## Adaptive Derivative-Assembled Pseudo-Trotter ansatz Variational Quantum Ei gensolver Files
- **`search.cpp/hpp`**: This file implements ADAPT-VQE based on this paper: https://www.nature.com/articles/s41467-019-10988-2.
- **`search_main.cpp/hpp`**: This is the main script for running the ADAPT-VQE algorithm.









7 changes: 7 additions & 0 deletions data_and_logs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Data and Logs

- [**Protein_Results/**](./Protein_Results) contains text files for metrics of protein experiments for each of the QSP methods.
- [**Protein_states_100/**](./Protein_states_100) contains 100 text files storing the protein-encoded quantum states generated by **protein.exp/uniprot.py**.
- [**Plots/**](./Plots) contains plots for the noisy simulation experiments.
- **`output.txt`**: This text file is a sampled output gate sequence from ISA.
- **`state.txt`**: This text file is a randomly sampled 5-qubit state.
18 changes: 9 additions & 9 deletions protein_exp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
Scripts for executing QSP implementations located in the `/cpp` directory and running protein experiments.

## Files
- **`isa_cpp_demo.py`**, **`vqc_cpp_demo.py`**, **`search_cpp_demo.py`**
Python scripts for the following QSP methods:
- **`isa_cpp_demo.py`**, **`search_cpp_demo.py`**, **`vqc_cpp_demo.py`**
These files are the scripts for the following QSP methods:
- **ISA (Iterated Sparse Approximation)**: `isa_cpp_demo.py`
- **ADAPT-VQE (Adaptive Variational Quantum Eigensolver)**: `vqc_cpp_demo.py`
- **AA-VQC (Altenrnating Ansatz - Variational Quantum Circuit)**: `search_cpp_demo.py`
Each script calls corresponding build files which compiles the corresponding C++ implementation from `/cpp`.
- **ADAPT-VQE (Adaptive Derivative-Assembled Pseudo-Trotter ansatz Variational Quantum Eigensolver)**: `search_cpp_demo.py`
- **AA-VQC (Altenrnating Ansatz - Variational Quantum Circuit)**: `vqc_cpp_demo.py`
Each script calls corresponding build files which compiles the corresponding C++ implementation from `/cpp`.

**Inputs**:
- Protein-encoded quantum states from `data_and_logs/Protein_states_100`.
- Fidelity threshold (>0.95).
- Fidelity threshold (>0.95)

**Outputs**:
The QSP implementation generates a gate sequence, used to calculate and save:
Expand All @@ -22,9 +22,9 @@ Scripts for executing QSP implementations located in the `/cpp` directory and ru
- **Fidelity**

**Results**:
- Metrics are stored in `data_and_logs/Protein_Results`.
- Metrics are stored in `data_and_logs/Protein_Results`

- **`uniprot.py`**: Generates protein-encoded states as `.txt` files using Uniprot Prot5 embeddings.
- **`ucg_exp.py`**: Conducts runtime experiments for **UCG (Uniformly Controlled Gates)**.
- **`uniprot.py`**: This sscipt generates protein-encoded states as `.txt` files using Uniprot Prot5 embeddings.
- **`ucg_exp.py`**: Conducts runtime experiments for **UCG (Uniformly Controlled Gates)**.


4 changes: 2 additions & 2 deletions qiskit_simulations/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
Files for ISA-based simulations on IBM devices.

## Files
- **`noisy_simulation.py`**: Prepares 100 random 5-qubit states using ISA. Fidelity thresholds are varied, and calculating ideal fidelity, noisy fidelity, and CX counts are calculated per state. Noisy simulations use IBM FakeMelbourneV2. Results are in `data_and_logs/Plots`.
- **`5_qubit_state.txt`**: Stores randomly generated states for ISA input.
- **`noisy_simulation.py`**: This script prepares 100 random 5-qubit states using ISA. Fidelity thresholds are varied, and ideal fidelity, noisy fidelity, and CX counts are calculated per state. The noisy simulations use IBM FakeMelbourneV2. The results are compiled in `data_and_logs/Plots`.
- **`5_qubit_state.txt`**: This file stores randomly generated states to be inputted into ISA.

0 comments on commit 91f014a

Please sign in to comment.