PySparQ.pysparq.algorithms.shor¶
Shor's Quantum Factorization Algorithm Implementation
Exceptions¶
Exception raised when Shor's algorithm fails to find factors. |
Classes¶
Modular exponentiation operation. |
|
Controlled modular multiplication operation. |
|
Semi-classical implementation of Shor's algorithm. |
|
Full quantum Shor's algorithm. |
Functions¶
|
Check if period is valid for factoring. |
|
Compute the period from measurement result. |
|
Generate a demo script for Shor's algorithm. |
|
Factor N using Shor's algorithm. |
|
Factor N using full quantum Shor's algorithm. |
|
Find the best fraction c/r approximating y/Q using Farey sequence. |
|
Compute a^x mod N efficiently using square-and-multiply. |
|
Classical post-processing for Shor's algorithm. |
Module Contents¶
- exception PySparQ.pysparq.algorithms.shor.ShorExecutionFailed[源代码]¶
Bases:
ExceptionException raised when Shor's algorithm fails to find factors.
Initialize self. See help(type(self)) for accurate signature.
- class PySparQ.pysparq.algorithms.shor.ExpMod(input_reg: str, output_reg: str, a: int, N: int, period: int)[源代码]¶
Modular exponentiation operation.
- class PySparQ.pysparq.algorithms.shor.ModMul(reg: str, a: int, x: int, N: int)[源代码]¶
Controlled modular multiplication operation.
- class PySparQ.pysparq.algorithms.shor.SemiClassicalShor(a: int, N: int)[源代码]¶
Semi-classical implementation of Shor's algorithm.
- class PySparQ.pysparq.algorithms.shor.Shor(work_reg: str, ancilla_reg: str, a: int, N: int, period: int)[源代码]¶
Full quantum Shor's algorithm.
- PySparQ.pysparq.algorithms.shor.check_period(period: int, a: int, N: int) None[源代码]¶
Check if period is valid for factoring.
- PySparQ.pysparq.algorithms.shor.compute_period(meas_result: int, size: int, N: int) int[源代码]¶
Compute the period from measurement result.
- PySparQ.pysparq.algorithms.shor.create_shor_demo() str[源代码]¶
Generate a demo script for Shor's algorithm.
- PySparQ.pysparq.algorithms.shor.factor(N: int, a: int | None = ...) tuple[int, int][源代码]¶
Factor N using Shor's algorithm.
- PySparQ.pysparq.algorithms.shor.factor_full_quantum(N: int, a: int | None = ...) tuple[int, int][源代码]¶
Factor N using full quantum Shor's algorithm.
- PySparQ.pysparq.algorithms.shor.find_best_fraction(y: int, Q: int, N: int) tuple[int, int][源代码]¶
Find the best fraction c/r approximating y/Q using Farey sequence.