Skip to content

Reproducing Results

Mohammadreza Khellat edited this page Dec 16, 2025 · 1 revision

Reproducing Results

Comprehensive guide for reproducing figures, outputs, and results from the openqcp-lab tutorials.


Table of Contents

  1. Prerequisites
  2. General Guidelines
  3. Tutorial-Specific Guides
  4. Troubleshooting Reproduction
  5. Version Compatibility
  6. Hardware vs Simulator

Prerequisites

Before reproducing results, ensure you have:

  1. Environment Setup: Completed setup as described in Getting Started
  2. Dependencies Installed: All packages from requirements.txt
  3. LaTeX (for some tutorials): Working LaTeX installation with cm-super package
  4. Sufficient Resources: Adequate memory and processing power for quantum simulations

General Guidelines

Execution Order

The notebooks are designed to be independent and can be run in any order. However, for a logical learning progression, see Learning Paths.

Expected Variations

Important: Some notebooks may produce slightly different results on each run due to:

  • Quantum Measurement Randomness: Inherent randomness in quantum measurements
  • Optimization Randomness: Random initial parameters in optimization algorithms
  • Numerical Precision: Floating-point arithmetic variations

This is expected behavior and does not indicate an error.

Reproducibility Tips

  1. Set Random Seeds: Where available, set random seeds for reproducibility:

    import numpy as np
    np.random.seed(42)  # For classical randomness
  2. Use Fixed Parameters: Use the same parameters as in the tutorial

  3. Sufficient Shots: Use adequate number of shots for quantum measurements

  4. Check Versions: Ensure you're using compatible package versions


Tutorial-Specific Guides

Tutorial 00: Quantum Fourier Transform

Notebook: quantum_fourier_transform_abelian/qft_abelian_qpe_hadamard.ipynb

Expected Outputs:

  • Plots showing expectation values
  • Measurement results displaying phase information
  • QFT transformation visualization

Optional Outputs:

  • qft-expvalue.qmod - Quantum model file (if write_qmod cell is executed)

Reproduction Steps:

  1. Navigate to quantum_fourier_transform_abelian/
  2. Open and run the notebook
  3. Execute cells sequentially
  4. Observe plots and measurement results

Verification:

  • Expectation values should show expected phase relationships
  • Measurement results should demonstrate QFT behavior
  • Plots should display correctly

Common Issues:

  • Classiq authentication may be required for some features
  • Plots may not display if matplotlib is not properly configured

Tutorial 01: Minimize Expectation Value

Notebook: minimize_expectation_value/minimize_vqc_output.ipynb

Expected Outputs:

  • Optimization convergence information
  • Final optimized parameters
  • Final expectation value

Reproduction Steps:

  1. Navigate to minimize_expectation_value/
  2. Open and run the notebook
  3. Execute optimization cells
  4. Observe convergence

Verification:

  • Expectation value should decrease over iterations
  • Optimization should converge (may take different number of iterations)
  • Final value should be close to expected minimum

Common Issues:

  • Optimization may not converge in exact same number of steps (expected)
  • Final value may vary slightly due to optimization randomness
  • Ensure PennyLane is properly installed

Tutorial 02: Quantum Walk

Notebook: quantum_walk/quantum_walk_discrete_time_line_16nodes.ipynb

Expected Outputs:

  • Quantum walk implementation results
  • Measurement results showing walk behavior
  • Demonstration of coin and shift operators

Reproduction Steps:

  1. Navigate to quantum_walk/
  2. Open and run the notebook
  3. Execute quantum walk cells
  4. Analyze measurement results

Verification:

  • Quantum walk should demonstrate expected behavior
  • Coin and shift operators should work correctly
  • Results should show quantum walk characteristics

Common Issues:

  • Classiq authentication may be required
  • Circuit complexity may affect execution time
  • Results may vary due to quantum measurement randomness

Tutorial 03: Non-Unitary Quantum Computing (LCU)

Notebook: nonunitary_quantum_computing/lcu_2x2.ipynb

Expected Outputs:

  • Measurement results showing non-unitary operator application
  • Verification of LCU implementation

Optional Outputs:

  • lcu-2x2.qmod - Quantum model file (if write_qmod cell is executed)

Reproduction Steps:

  1. Navigate to nonunitary_quantum_computing/
  2. Open and run the notebook
  3. Execute LCU implementation cells
  4. Verify non-unitary operation

Verification:

  • Non-unitary operator should be applied correctly
  • Measurement results should match expected behavior
  • LCU decomposition should work as expected

Common Issues:

  • Understanding LCU decomposition may require review of theory
  • Results should verify non-unitary operation application

Tutorial 04: Quantum Variational Algorithms

Notebook: quantum_variational_algorithms/VA0_qubo_and_vqe.ipynb

Expected Outputs:

  • VQE optimization results
  • Ground state energy
  • Optimized parameters
  • Solution to QUBO/Max-Cut problem

Reproduction Steps:

  1. Navigate to quantum_variational_algorithms/
  2. Open and run the notebook
  3. Execute VQE optimization
  4. Extract solution

Verification:

  • VQE should converge to ground state
  • Ground state energy should be reasonable
  • Solution should satisfy problem constraints
  • Optimization should complete successfully

Common Issues:

  • Optimization may take different number of iterations
  • Final energy may vary slightly
  • Ensure Qiskit is installed (optional dependency)
  • May need to install: pip install qiskit qiskit-optimization

Tutorial 05: Coupled Harmonic Oscillators

Notebook: coupled_harmonic_oscillators/N_coupled_harmonic_oscillators_1_D_N_2.ipynb

Expected Outputs:

  • Figures:

    • figures/hs_n_2.png - Hamiltonian simulation results (Cell 49)
    • figures/ar_n_2.png - Analytical solution comparison (Cell 59)
  • Quantum Model Files (Optional):

    • N-2-dt-*.qmod - Quantum model files
    • N-2-dt-*.qprog - Quantum program files

Reproduction Steps:

  1. Navigate to coupled_harmonic_oscillators/
  2. Open and run the notebook
  3. Execute simulation cells
  4. Generate figures (Cells 49 and 59)

To Save Figures: Add plt.savefig('figures/filename.png') before plt.show() in:

  • Cell 49: For Hamiltonian simulation plot
  • Cell 59: For analytical solution plot

Verification:

  • Quantum simulation should match analytical solution
  • Figures should display correctly
  • Hamiltonian simulation should show expected dynamics
  • Comparison plots should demonstrate agreement

Common Issues:

  • LaTeX Errors: Install LaTeX and cm-super package, or disable LaTeX rendering
  • Execution Time: Simulation may take several minutes
  • Figure Generation: Ensure figures/ directory exists
  • Quantum Model Files: Generated only if write_qmod cells are executed

Physical Parameters (for verification):

  • Masses: ${ m_0 = 1.0, m_1 = 2.0 }$
  • Spring constants: $k_{00} = 1.0$, $k_{01} = 2.0$, $k_{11} = 3.0$
  • Initial conditions: ${ \dot{y}_0(0) = 1.0, \dot{y}_1(0) = -1.0, y_0(0) = 0.0, y_1(0) = 0.0 }$

Troubleshooting Reproduction

Figures Not Rendering Properly

Symptoms:

  • Mathematical notation appears incorrectly
  • Plots don't display
  • LaTeX errors in plots

Solutions:

  1. LaTeX Issues:

    • Install LaTeX distribution (TeX Live, MiKTeX, or MacTeX)
    • Install cm-super package
    • Or disable LaTeX: plt.rcParams['text.usetex'] = False
  2. Matplotlib Issues:

    • Ensure matplotlib is installed: pip install matplotlib
    • Use %matplotlib inline in Jupyter
    • Check that cells executed successfully
  3. Display Issues:

    • Use plt.show() to display plots
    • Check Jupyter display settings
    • Try different backends if needed

Quantum Model Files Not Generated

Symptoms:

  • .qmod or .qprog files not created
  • write_qmod errors

Solutions:

  1. Permissions:

    • Ensure write permissions in notebook directory
    • Check that directory exists and is writable
  2. Execution:

    • Verify write_qmod cell executed without errors
    • Check Classiq authentication if required
    • Review cell output for error messages
  3. File Location:

    • Files are saved in the notebook's directory
    • Check current working directory
    • Verify file paths are correct

Execution Errors

Symptoms:

  • Notebooks fail to execute
  • Import errors
  • Runtime errors

Solutions:

  1. Dependencies:

    • Verify all dependencies: pip install -r requirements.txt
    • Check Python version (3.9+ recommended)
    • Update packages if needed
  2. Environment:

    • Ensure virtual environment is activated
    • Check that you're in the correct directory
    • Verify kernel selection in Jupyter
  3. Framework-Specific:

    • Classiq: Check authentication if required
    • PennyLane: Verify backend availability
    • Qiskit: Check installation and optional dependencies

Results Don't Match Expected

Symptoms:

  • Results differ from tutorial
  • Significant variations in outputs

Solutions:

  1. Expected Variations:

    • Quantum measurement randomness is normal
    • Optimization may converge differently
    • Numerical precision variations are expected
  2. Parameter Verification:

    • Check that parameters match tutorial
    • Verify initial conditions
    • Ensure random seeds are set (if applicable)
  3. Version Compatibility:


Version Compatibility

Recommended Versions

  • Python: 3.9 or later
  • NumPy: >= 1.20.0
  • SciPy: >= 1.7.0
  • Matplotlib: >= 3.4.0
  • Classiq: >= 0.20.0
  • PennyLane: >= 0.28.0
  • Qiskit: >= 0.45.0 (optional)

Checking Versions

import numpy as np
import scipy
import matplotlib
import classiq
import pennylane as qml

print("NumPy:", np.__version__)
print("SciPy:", scipy.__version__)
print("Matplotlib:", matplotlib.__version__)
print("Classiq:", classiq.__version__)
print("PennyLane:", qml.__version__)

Updating Packages

pip install --upgrade numpy scipy matplotlib classiq pennylane
# For Qiskit (optional):
pip install --upgrade qiskit qiskit-optimization

Hardware vs Simulator

Using Simulators

Default Behavior:

  • Most tutorials use quantum simulators by default
  • Simulators provide deterministic results (except measurement randomness)
  • Faster execution for development and testing

Advantages:

  • No hardware access required
  • Faster iteration
  • Reproducible results (with fixed seeds)
  • No queue times

Using Quantum Hardware

When to Use:

  • Testing on real quantum devices
  • Demonstrating hardware capabilities
  • Research requiring hardware results

Considerations:

  • Access Required: Need account/API access
  • Queue Times: May need to wait for execution
  • Noise: Real hardware has noise and errors
  • Limited Qubits: Hardware limitations
  • Cost: May have usage costs

Setup:

  • Qiskit: Requires IBM Quantum account
  • PennyLane: Supports various hardware backends
  • Classiq: Limited hardware access

Additional Notes

Execution Time

Execution times vary significantly depending on:

  • Number of Shots: More shots = longer execution
  • Circuit Complexity: Larger circuits take longer
  • Optimization Iterations: More iterations = longer optimization
  • Hardware vs Simulator: Hardware may be slower due to queue times

Randomness

Some randomness is expected and normal:

  • Quantum Measurements: Inherently random
  • Optimization: Random initial parameters
  • Numerical Methods: Floating-point variations

Performance Tips

  1. Reduce Shots: Use fewer shots for faster execution during development
  2. Smaller Problems: Test with smaller problem sizes first
  3. Simulator First: Use simulators for development, hardware for final runs
  4. Optimize Code: Profile and optimize slow sections

Getting Help

If you encounter issues reproducing results:

  1. Check Documentation:

  2. Verify Setup:

    • Ensure environment is set up correctly
    • Check all dependencies are installed
    • Verify package versions
  3. Report Issues:

    • Open an issue on Codeberg
    • Include error messages and system information
    • Specify which tutorial and cell

Return to: Home | Tutorial Catalog | Getting Started

Clone this wiki locally