braket.experimental.algorithms.shors.shors module
- braket.experimental.algorithms.shors.shors.shors_algorithm(integer_N: int, integer_a: int) Circuit[source]
- Creates the circuit for Shor’s algorithm.
Based on integer N, calculate number of counting qubits for the first register
Setup same number of auxiliary qubits for the second register and apply modular exponentian function
Apply inverse_QFT
- Parameters:
integer_N (int) – The integer N to be factored
integer_a (int) – Any integer ‘a’ that satisfies 1 < a < N and gcd(a, N) = 1.
- Returns:
Circuit – Circuit object that implements the Shor’s algorithm
- braket.experimental.algorithms.shors.shors.run_shors_algorithm(circuit: Circuit, device: Device, shots: int | None = 1000) Dict[str, Any][source]
Function to run Shor’s algorithm and return measurement counts.
- Parameters:
circuit (Circuit) – Shor’s algorithm circuit
device (Device) – Braket device backend
shots (Optional[int]) – Number of measurement shots (default is 1000). 0 shots results in no measurement.
- Returns:
Dict[str, Any] – measurements and results from running Shors’s algorithm
- braket.experimental.algorithms.shors.shors.inverse_qft_noswaps(qubits: Qubit | int | Iterable[Qubit | int]) Circuit[source]
Construct a circuit object corresponding to the inverse Quantum Fourier Transform (QFT) algorithm, applied to the argument qubits. Does not use recursion to generate the circuit.
- Parameters:
qubits (QubitSetInput) – Qubits on which to apply the inverse Quantum Fourier Transform
- Returns:
Circuit – Circuit object that implements the inverse Quantum Fourier Transform algorithm
- braket.experimental.algorithms.shors.shors.modular_exponentiation_amod15(counting_qubits: Qubit | int | Iterable[Qubit | int], aux_qubits: Qubit | int | Iterable[Qubit | int], integer_a: int) Circuit[source]
Construct a circuit object corresponding the modular exponentiation of a^x Mod 15
- Parameters:
counting_qubits (QubitSetInput) – Qubits defining the counting register
aux_qubits (QubitSetInput) – Qubits defining the auxilary register
integer_a (int) – Any integer that satisfies 1 < a < N and gcd(a, N) = 1.
- Returns:
Circuit – Circuit object that implements the modular exponentiation of a^x Mod 15
- braket.experimental.algorithms.shors.shors.get_factors_from_results(results: Dict[str, Any], integer_N: int, integer_a: int, verbose: bool = True) Dict[str, Any][source]
- Function to postprocess dictionary returned by run_shors_algorithm
and pretty print results
- Parameters:
results (Dict[str, Any]) – Results associated with quantum phase estimation run as produced by run_shors_algorithm
integer_N (int) – The integer to be factored
integer_a (int) – Any integer that satisfies 1 < a < N and gcd(a, N) = 1.
verbose (bool) – If True, prints aggregate results (default is False)
- Returns:
Dict[str, Any] – Factors of the integer N