forked from usra-riacs/stochastic-benchmark
-
Notifications
You must be signed in to change notification settings - Fork 2
Resolve review comments: Fix unit tests and cleanup artifacts (new) #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
7aa1177
Fix unit tests, apply whitespace formatting, update .gitignore, and c…
anurag-r20 f39b4f9
Changed .gitignore to only ignore data and files relevant to IBM_QAOA
anurag-r20 93dbe43
chore: update .gitignore for examples and data artifacts
anurag-r20 6d78673
test: add IBM QAOA test fixtures
anurag-r20 1cd6967
test: add comprehensive test suite for IBM QAOA processing
anurag-r20 0d71087
feat: add performance optimizations to IBM QAOA processing
anurag-r20 804a03f
docs: add performance optimization roadmap
anurag-r20 0d9bff8
chore: clear notebook outputs in ibm_qaoa_analysis
anurag-r20 bef72e2
feat: add hardware analysis notebook for IBM QAOA
anurag-r20 7b929fc
refactor: move Pandas group tests to main tests directory
anurag-r20 cba3085
README.md edit minor corrections in .json file nomencalture
anurag-r20 3ac09b8
feat: add support for multiple marker types based on optimization flags
anurag-r20 927644c
Add minmax cuts integration for approximation ratio calculation
anurag-r20 009316a
Add integration test for minmax cuts functionality
anurag-r20 b533a7b
Update analysis notebook with latest cell outputs
anurag-r20 e030ffe
Separate opt and noOpt variants as independent methods in cross-metho…
anurag-r20 af173ef
Archived old code, started new processing script
anurag-r20 5969631
Moved old code to archive
anurag-r20 a3e3f62
Major revisions to training class
anurag-r20 fc26b25
Minor revisions to QAOA training class
anurag-r20 78e8c6d
Create src/ for Processing.py, notebooks/ for Analysis.ipynb
anurag-r20 4400217
Minor changes to Analysis.ipynb
anurag-r20 a1ced14
Added DataFrame based analysis and script to evaluate approx ratio fo…
anurag-r20 269d519
Script and notebook modification to calucate approximation ratios
anurag-r20 3956d56
Succesful integration of approx ratio calculation for maxcut + IVM QA…
anurag-r20 dbe9943
Minor fix on QPU_time and num_shots
anurag-r20 1d5f74c
IBM QAOA training data analysis version 1.0
anurag-r20 302726d
Preliminary clean up for training DataFrame
anurag-r20 0d58f3b
minor fix to tables
anurag-r20 a5800fd
Doctring added to functions and classes. Version 1.0 ready
anurag-r20 6ee6034
Revert conversion.ipynb to upstream version
anurag-r20 f57a7d6
Create utils.py, extract instance specific details in DataFrame
anurag-r20 f45c206
Generated final DataFrame for performance plots
anurag-r20 b09f4a8
Fixed changes reviewed in PR for Archived code
anurag-r20 0e63984
Cleaned and up to date notebooks, processing files and README.md
anurag-r20 3f382fe
Move archived IBM QAOA tests out of main test suite
anurag-r20 63b4887
Clean scripts
anurag-r20 9e18ff5
Added markdown for Analysis.ipynb, random seed for iterative QAOA not…
anurag-r20 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,204 @@ | ||
| # IBM QAOA Data Processing | ||
|
|
||
| This directory contains tools for processing IBM quantum hardware QAOA (Quantum Approximate Optimization Algorithm) experimental data for MaxCut problems. | ||
|
|
||
| ## Directory Structure | ||
|
|
||
| The processing pipeline requires N-based subdirectory organization: | ||
|
|
||
| ``` | ||
| IBM_QAOA/ | ||
| ├── instances/ | ||
| │ ├── random_regular/N{n}/*.json # R3R problem instances | ||
| │ └── heavy_hex/N{n}/*.json # Heavy-hex problem instances | ||
| ├── R3R/ | ||
| │ └── minmax_cuts/N{n}/*.json # Minmax cuts for R3R | ||
| ├── heavy_hex/ | ||
| │ └── minmax_cuts/N{n}/*.json # Minmax cuts for heavy-hex | ||
| ├── R3R_results_hardware/ # Hardware results (R3R topology) | ||
| ├── heavy_hex_results_hardware/ # Hardware results (heavy-hex topology) | ||
| └── ibm_qaoa_processing.py # Main processing script | ||
| ``` | ||
|
|
||
| **Note**: All data must be organized in N-based subdirectories (e.g., `N40/`, `N144/`). Flat structures are not supported. | ||
|
|
||
| ## Key Terminology | ||
|
|
||
| ### QAOA Parameters | ||
| - **p** (QAOA layers): Number of parameter layers in QAOA circuit | ||
| - Each layer consists of a pair of parameters (γ, β) | ||
| - Common values: p = 2, 4, 5, 6, 10 | ||
| - ⚠️ **Not** circuit depth (which includes all gates) | ||
|
|
||
| ### Qubit Terminology | ||
| - **Program qubits**: Qubits as defined in the problem Hamiltonian (pre-mapping) | ||
| - **Physical qubits**: Actual hardware qubits after SAT mapping | ||
| - **Edge map**: Dictionary mapping program qubit indices to physical qubit indices | ||
|
|
||
| ### Energy and Cut Values | ||
| - **eval_energy**: QAOA expectation value `<H>` from hardware (can be positive or negative) | ||
| - **cut_value**: Sum of weights for edges crossing the partition (always positive) | ||
| - **Approximation ratio**: Performance metric in range [0, 1] | ||
|
|
||
| ## Energy Convention | ||
|
|
||
| QAOA for MaxCut uses the Hamiltonian: | ||
|
|
||
| ``` | ||
| H = -0.5 * Σ w_ij (1 - Z_i Z_j) for all edges (i,j) | ||
| ``` | ||
|
|
||
| Key conversions: | ||
| ```python | ||
| # Transform QAOA energy to cut value | ||
| cut_val = eval_energy + 0.5 * sum_weights | ||
|
|
||
| # Calculate approximation ratio | ||
| approx_ratio = (cut_val - min_cut) / (max_cut - min_cut) | ||
| ``` | ||
|
|
||
| ## Processing Pipeline | ||
|
|
||
| ### 1. Load Instance Data | ||
| ```python | ||
| edges = load_instance_file(instance_id, n_nodes, topology='R3R') | ||
| # Returns: Dict[(i,j), weight] for program qubits | ||
| ``` | ||
|
|
||
| ### 2. Load Minmax Cuts | ||
| ```python | ||
| minmax_data = load_minmax_cuts(minmax_dir='R3R/minmax_cuts', n_nodes=40) | ||
| # Returns: Dict with min_cut, max_cut, sum_weights for each instance | ||
| ``` | ||
|
|
||
| ### 3. Process Hardware Trials | ||
| ```python | ||
| result = parse_hardware_trial(trial_data, instance_id, depth, minmax_data, topology) | ||
| # Returns: QAOAResult with approximation_ratio, bitstring_cut_values, etc. | ||
| ``` | ||
|
|
||
| ### 4. Convert to DataFrame | ||
| ```python | ||
| df = results_to_dataframe(results, parameter_names) | ||
| # Returns: DataFrame with columns: instance, p, Approximation_Ratio, MeanTime, etc. | ||
| ``` | ||
|
|
||
| ## Quick Start | ||
|
|
||
| ```python | ||
| import ibm_qaoa_processing as ibm | ||
|
|
||
| # Process hardware data | ||
| sb, agg_df = ibm.process_qaoa_data( | ||
| json_pattern='heavy_hex_results_hardware/N144/*.json', | ||
| output_dir='heavy_hex_results_hardware', | ||
| n_nodes=144, | ||
| topology='heavy_hex', | ||
| minmax_dir='heavy_hex/minmax_cuts' | ||
| ) | ||
|
|
||
| # View results | ||
| print(agg_df[['instance', 'p', 'Approximation_Ratio', 'method']].head()) | ||
| ``` | ||
|
|
||
| ## Data Files | ||
|
|
||
| ### Instance Files | ||
| Format: `{instance_id}_{params}_weighted.json` | ||
| ```json | ||
| { | ||
| "edge list": [ | ||
| {"nodes": [0, 1], "weight": 1.0}, | ||
| {"nodes": [1, 2], "weight": 1.0} | ||
| ], | ||
| "Description": "..." | ||
| } | ||
| ``` | ||
|
|
||
| ### Minmax Cuts Files | ||
| Format: `{instance_id}_{params}_maxmin_cut.json` | ||
| ```json | ||
| { | ||
| "min_cut": 20.0, | ||
| "max_cut": 80.0, | ||
| "sum_of_weights": 100.0, | ||
| "instance": "instances/random_regular/000_40nodes_random3regular.json" | ||
| } | ||
| ``` | ||
|
|
||
| ### Hardware Results Files | ||
| Format: `{method}_{instance_id}_p{p}_{hash}.json` | ||
| ```json | ||
| { | ||
| "trial_data": { | ||
| "counts": {"0101...": 1, "1010...": 1} | ||
| }, | ||
| "circuit_metadata": { | ||
| "eval_energy": 10.5, | ||
| "params": [0.5, 1.2, ...], | ||
| "trainer": "FA_PP_opt_10" | ||
| }, | ||
| "sat_mapper": { | ||
| "edge_map": {"0": 0, "1": 5, ...}, | ||
| "duration": 12.3 | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## Topologies | ||
|
|
||
| ### R3R (Random 3-Regular) | ||
| - **Structure**: Random 3-regular graphs | ||
| - **Node counts**: 10, 20, 40, 50, 60, 70 (All nodes not available for all methods) | ||
| - **SAT mapping**: Non-identity (requires bitstring remapping) | ||
| - **QAOA Parameter training methods tested**: F, FA, I, TQA, TS, RTS | ||
|
|
||
| ### Heavy-Hex | ||
| - **Structure**: IBM native heavy-hex topology | ||
| - **Node counts**: 12, 39, 105, 106, 144 (All nodes not available for all methods) | ||
| - **SAT mapping**: Identity mapping (no remapping needed) | ||
| - **Methods tested**: F, I, TQA | ||
|
|
||
| ## Common Issues | ||
|
|
||
| ### 1. Approximation Ratios > 1 | ||
| **Solution**: Fixed by applying the canonical energy-to-cut transformation: `cut_val = energy + 0.5 * sum_weights`. The `evaluate_bitstring_cut_value()` function now returns cut values directly. | ||
|
|
||
| ### 2. Missing N-based Subdirectory | ||
| **Error**: `ValueError: N-based subdirectory not found` | ||
| **Solution**: Organize files in N-based subdirectories (e.g., `minmax_cuts/N40/`) | ||
|
|
||
| ### 3. Bitstring Length Mismatch | ||
| **Warning**: `Bitstring length != edge_map size` | ||
| **Cause**: Hardware measurement on wrong number of qubits | ||
| **Impact**: Mismatched bitstrings are skipped | ||
|
|
||
| ## Analysis Notebook | ||
|
|
||
| See `ibm_qaoa_analysis_hardware.ipynb` and - `ibm_qaoa_analysis.ipynb` for: | ||
| - Data loading and exploration | ||
| - Approximation ratio analysis by method and p | ||
| - Performance comparisons across topologies | ||
| - Bootstrap analysis for confidence intervals | ||
|
|
||
| ## Files | ||
|
|
||
| - `ibm_qaoa_processing.py` - Main processing pipeline | ||
| - `ibm_qaoa_analysis.ipynb` - Simulation results analysis notebook | ||
| - `ibm_qaoa_analysis_hardware.ipynb` - Hardware results analysis notebook | ||
| - `transfer_simulation_data.py` - Transfer simulation experiment data from source repository | ||
| - `transfer_hardware_data.py` - Transfer hardware experiment data from source repository | ||
| - `test_approx_ratio_fix.py` - Validation tests for approximation ratio fix | ||
| - `demo_realistic_fix.py` - Demonstration with realistic values | ||
|
|
||
| ## References | ||
|
|
||
| - **QAOA-Parameter-Setting repository**: https://github.com/Quantum-Working-Groups/QAOA-Parameter-Setting | ||
|
|
||
| - **Stochastic Benchmark framework**: Performance and statistical analysis tools https://github.com/usra-riacs/stochastic-benchmark | ||
|
|
||
| - **IBM Quantum**: Hardware execution platform https://www.ibm.com/quantum | ||
|
|
||
| ## Contact | ||
|
|
||
| For questions about the data or processing pipeline, refer to the QAOA-Parameter-Setting repository. | ||
|
anurag-r20 marked this conversation as resolved.
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.