Quantum period finding algorithm for Shor's algorithm.
This algorithm is a specialized application of quantum phase estimation (QPE) to find the period of the modular exponentiation function f(x) = a^x mod N.
Instead of reimplementing QPE, this module leverages the existing quantum-phase-estimation algorithm and adapts it for period finding by:
This follows the DRY principle and maintains a clean separation of concerns.
Quantum period finding algorithm for Shor's algorithm. This algorithm is a specialized application of quantum phase estimation (QPE) to find the period of the modular exponentiation function f(x) = a^x mod N. Instead of reimplementing QPE, this module leverages the existing quantum-phase-estimation algorithm and adapts it for period finding by: 1. Setting up the appropriate unitary operator (modular exponentiation) 2. Using QPE to estimate the phase 3. Converting phase estimates to period estimates using continued fractions This follows the DRY principle and maintains a clean separation of concerns.
(phase-to-period phase precision-qubits N a)
Convert a phase estimate from QPE to a period estimate for modular exponentiation.
In quantum period finding, we're estimating the phase φ where the eigenvalue of the modular exponentiation unitary is e^(iφ). The period r relates to the phase through: φ = 2πs/r for some integer s.
We use continued fractions to find the best rational approximation s/r where r is likely to be the period.
Parameters:
Returns: Map with period estimate or nil if no valid period found
Convert a phase estimate from QPE to a period estimate for modular exponentiation. In quantum period finding, we're estimating the phase φ where the eigenvalue of the modular exponentiation unitary is e^(iφ). The period r relates to the phase through: φ = 2πs/r for some integer s. We use continued fractions to find the best rational approximation s/r where r is likely to be the period. Parameters: - phase: Estimated phase from QPE - precision-qubits: Number of precision qubits used in QPE - N: Modulus for period finding - a: Base for modular exponentiation a^x mod N Returns: Map with period estimate or nil if no valid period found
(quantum-period-finding backend a N precision-qubits)
(quantum-period-finding backend a N precision-qubits n-measurements)
(quantum-period-finding backend a N precision-qubits n-measurements options)
Find the period of f(x) = a^x mod N using quantum phase estimation.
This function is a specialized application of quantum phase estimation for period finding in Shor's algorithm. It uses a generalized QPE that works with modular exponentiation as the unitary operator.
The approach:
Parameters:
Returns: Map containing:
Find the period of f(x) = a^x mod N using quantum phase estimation. This function is a specialized application of quantum phase estimation for period finding in Shor's algorithm. It uses a generalized QPE that works with modular exponentiation as the unitary operator. The approach: 1. Use generalized QPE with modular exponentiation as the controlled unitary 2. Convert phase measurement results to period estimates using continued fractions 3. Return the most likely period with statistical confidence Parameters: - backend: Quantum backend implementing the QuantumBackend protocol - a: Base for the function f(x) = a^x mod N - N: Modulus - precision-qubits: Number of qubits for phase precision (affects accuracy) - n-measurements: (optional) Number of measurements for statistical analysis (default: 1) - options: (optional) Map containing additional backend options Returns: Map containing: - :estimated-period - Most likely period estimate - :period-candidates - All valid period candidates with probabilities - :qpe-results - Raw results from quantum phase estimation - :success - Whether a valid period was found - :confidence - Statistical confidence in the result
(quantum-phase-estimation-circuit precision-qubits
eigenstate-qubits
eigenstate-prep-fn
controlled-unitary-fn)
Create a quantum circuit for phase estimation with specified precision and eigenstate qubits.
This function builds the quantum circuit for phase estimation, including:
Parameters:
Returns: Quantum circuit ready for execution
Create a quantum circuit for phase estimation with specified precision and eigenstate qubits. This function builds the quantum circuit for phase estimation, including: 1. Preparing the eigenstate qubits 2. Initializing precision qubits in superposition 3. Applying controlled unitary operations 4. Applying inverse quantum Fourier transform (QFT) Parameters: - precision-qubits: Number of qubits for phase precision - eigenstate-qubits: Number of qubits for eigenstate preparation Returns: Quantum circuit ready for execution
(quantum-phase-estimation-with-custom-unitary backend
precision-qubits
eigenstate-qubits
eigenstate-prep-fn
controlled-unitary-fn
options)
Perform generalized quantum phase estimation with custom unitary operations.
This function implements a generalized version of quantum phase estimation that allows for custom controlled unitary operations, enabling it to work with any unitary operator, not just phase rotations.
Parameters:
Returns: Map containing:
Perform generalized quantum phase estimation with custom unitary operations. This function implements a generalized version of quantum phase estimation that allows for custom controlled unitary operations, enabling it to work with any unitary operator, not just phase rotations. Parameters: - backend: Quantum backend implementing the QuantumBackend protocol - precision-qubits: Number of qubits for phase precision (affects accuracy) - eigenstate-qubits: Number of qubits for eigenstate preparation - eigenstate-prep-fn: Function to prepare the eigenstate (receives circuit and eigenstate qubit range) - controlled-unitary-fn: Function to apply controlled U^(2^k) operations (receives circuit, control qubit, power, and eigenstate qubit range) - options: Map containing additional backend options (e.g., :shots, :n-measurements) Returns: Map containing: - :measurements - Combined measurement results from all executions - :circuit - The quantum circuit used for QPE - :execution-results - Results from all circuit executions - :precision-qubits - Number of precision qubits used - :eigenstate-qubits - Number of eigenstate qubits used - :n-measurements - Number of measurements performed
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close