-
Notifications
You must be signed in to change notification settings - Fork 0
Reproducing Results
Comprehensive guide for reproducing figures, outputs, and results from the openqcp-lab tutorials.
- Prerequisites
- General Guidelines
- Tutorial-Specific Guides
- Troubleshooting Reproduction
- Version Compatibility
- Hardware vs Simulator
Before reproducing results, ensure you have:
- Environment Setup: Completed setup as described in Getting Started
-
Dependencies Installed: All packages from
requirements.txt -
LaTeX (for some tutorials): Working LaTeX installation with
cm-superpackage - Sufficient Resources: Adequate memory and processing power for quantum simulations
The notebooks are designed to be independent and can be run in any order. However, for a logical learning progression, see Learning Paths.
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.
-
Set Random Seeds: Where available, set random seeds for reproducibility:
import numpy as np np.random.seed(42) # For classical randomness
-
Use Fixed Parameters: Use the same parameters as in the tutorial
-
Sufficient Shots: Use adequate number of shots for quantum measurements
-
Check Versions: Ensure you're using compatible package versions
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 (ifwrite_qmodcell is executed)
Reproduction Steps:
- Navigate to
quantum_fourier_transform_abelian/ - Open and run the notebook
- Execute cells sequentially
- 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
Notebook: minimize_expectation_value/minimize_vqc_output.ipynb
Expected Outputs:
- Optimization convergence information
- Final optimized parameters
- Final expectation value
Reproduction Steps:
- Navigate to
minimize_expectation_value/ - Open and run the notebook
- Execute optimization cells
- 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
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:
- Navigate to
quantum_walk/ - Open and run the notebook
- Execute quantum walk cells
- 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
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 (ifwrite_qmodcell is executed)
Reproduction Steps:
- Navigate to
nonunitary_quantum_computing/ - Open and run the notebook
- Execute LCU implementation cells
- 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
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:
- Navigate to
quantum_variational_algorithms/ - Open and run the notebook
- Execute VQE optimization
- 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
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:
- Navigate to
coupled_harmonic_oscillators/ - Open and run the notebook
- Execute simulation cells
- 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-superpackage, or disable LaTeX rendering - Execution Time: Simulation may take several minutes
-
Figure Generation: Ensure
figures/directory exists -
Quantum Model Files: Generated only if
write_qmodcells 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 }$
Symptoms:
- Mathematical notation appears incorrectly
- Plots don't display
- LaTeX errors in plots
Solutions:
-
LaTeX Issues:
- Install LaTeX distribution (TeX Live, MiKTeX, or MacTeX)
- Install
cm-superpackage - Or disable LaTeX:
plt.rcParams['text.usetex'] = False
-
Matplotlib Issues:
- Ensure matplotlib is installed:
pip install matplotlib - Use
%matplotlib inlinein Jupyter - Check that cells executed successfully
- Ensure matplotlib is installed:
-
Display Issues:
- Use
plt.show()to display plots - Check Jupyter display settings
- Try different backends if needed
- Use
Symptoms:
-
.qmodor.qprogfiles not created -
write_qmoderrors
Solutions:
-
Permissions:
- Ensure write permissions in notebook directory
- Check that directory exists and is writable
-
Execution:
- Verify
write_qmodcell executed without errors - Check Classiq authentication if required
- Review cell output for error messages
- Verify
-
File Location:
- Files are saved in the notebook's directory
- Check current working directory
- Verify file paths are correct
Symptoms:
- Notebooks fail to execute
- Import errors
- Runtime errors
Solutions:
-
Dependencies:
- Verify all dependencies:
pip install -r requirements.txt - Check Python version (3.9+ recommended)
- Update packages if needed
- Verify all dependencies:
-
Environment:
- Ensure virtual environment is activated
- Check that you're in the correct directory
- Verify kernel selection in Jupyter
-
Framework-Specific:
- Classiq: Check authentication if required
- PennyLane: Verify backend availability
- Qiskit: Check installation and optional dependencies
Symptoms:
- Results differ from tutorial
- Significant variations in outputs
Solutions:
-
Expected Variations:
- Quantum measurement randomness is normal
- Optimization may converge differently
- Numerical precision variations are expected
-
Parameter Verification:
- Check that parameters match tutorial
- Verify initial conditions
- Ensure random seeds are set (if applicable)
-
Version Compatibility:
- Check package versions
- Update to compatible versions if needed
- See Version Compatibility
- 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)
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__)pip install --upgrade numpy scipy matplotlib classiq pennylane
# For Qiskit (optional):
pip install --upgrade qiskit qiskit-optimizationDefault 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
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
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
Some randomness is expected and normal:
- Quantum Measurements: Inherently random
- Optimization: Random initial parameters
- Numerical Methods: Floating-point variations
- Reduce Shots: Use fewer shots for faster execution during development
- Smaller Problems: Test with smaller problem sizes first
- Simulator First: Use simulators for development, hardware for final runs
- Optimize Code: Profile and optimize slow sections
If you encounter issues reproducing results:
-
Check Documentation:
- Review Getting Started
- See FAQ for common issues
- Check individual tutorial pages
-
Verify Setup:
- Ensure environment is set up correctly
- Check all dependencies are installed
- Verify package versions
-
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