Skip to main contentIBM Quantum Documentation
This page is from an old version of Qiskit SDK and does not exist in the latest version. We recommend you migrate to the latest version. See the release notes for more information.

qiskit.aqua.algorithms.Shor

class Shor(N=15, a=2, quantum_instance=None)

GitHub

Shor’s factoring algorithm.

Shor’s Factoring algorithm is one of the most well-known quantum algorithms and finds the prime factors for input integer NN in polynomial time.

The input integer NN to be factored is expected to be odd and greater than 2. Even though this implementation is general, its capability will be limited by the capacity of the simulator/hardware. Another input integer aa can also be supplied, which needs to be a co-prime smaller than NN .

Adapted from https://github.com/ttlion/ShorAlgQiskit

See also https://arxiv.org/abs/quant-ph/0205095

Parameters

  • N (int) – The integer to be factored, has a min. value of 3.

  • a (int) – Any integer that satisfies 1 < a < N and gcd(a, N) = 1.

  • quantum_instance (Union[QuantumInstance, Backend, BaseBackend, None]) –

    Quantum Instance or Backend

    Raises:

    ValueError: Invalid input

__init__

__init__(N=15, a=2, quantum_instance=None)

Parameters

  • N (int) – The integer to be factored, has a min. value of 3.

  • a (int) – Any integer that satisfies 1 < a < N and gcd(a, N) = 1.

  • quantum_instance (Union[QuantumInstance, Backend, BaseBackend, None]) –

    Quantum Instance or Backend

    Raises:

    ValueError: Invalid input


Methods

__init__([N, a, quantum_instance])type Nint
construct_circuit([measurement])Construct circuit.
modinv(a, m)Returns the modular multiplicative inverse of a with respect to the modulus m.
run([quantum_instance])Execute the algorithm with selected backend.
set_backend(backend, **kwargs)Sets backend with configuration.

Attributes

backendReturns backend.
quantum_instanceReturns quantum instance.
randomReturn a numpy random.

backend

Returns backend.

Return type

Union[Backend, BaseBackend]

construct_circuit

construct_circuit(measurement=False)

Construct circuit.

Parameters

measurement (bool) – Boolean flag to indicate if measurement should be included in the circuit.

Return type

QuantumCircuit

Returns

Quantum circuit.

modinv

static modinv(a, m)

Returns the modular multiplicative inverse of a with respect to the modulus m.

Return type

int

quantum_instance

Returns quantum instance.

Return type

Optional[QuantumInstance]

random

Return a numpy random.

run

run(quantum_instance=None, **kwargs)

Execute the algorithm with selected backend.

Parameters

  • quantum_instance (Union[QuantumInstance, Backend, BaseBackend, None]) – the experimental setting.
  • kwargs (dict) – kwargs

Returns

results of an algorithm.

Return type

dict

Raises

AquaError – If a quantum instance or backend has not been provided

set_backend

set_backend(backend, **kwargs)

Sets backend with configuration.

Return type

None

Was this page helpful?
Report a bug or request content on GitHub.