# qiskit.aqua.algorithms.Shor¶

class Shor(N=15, a=2, quantum_instance=None)[código fonte]

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 $$N$$ in polynomial time.

The input integer $$N$$ 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 $$a$$ can also be supplied, which needs to be a co-prime smaller than $$N$$ .

Parâmetros
• 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__(N=15, a=2, quantum_instance=None)[código fonte]
Parâmetros
• 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 N int 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

 backend Returns backend. quantum_instance Returns quantum instance. random Return a numpy random.
property backend

Returns backend.

Tipo de retorno

Union[Backend, BaseBackend]

construct_circuit(measurement=False)[código fonte]

Construct circuit.

Parâmetros

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

Tipo de retorno

QuantumCircuit

Retorna

Quantum circuit.

static modinv(a, m)[código fonte]

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

Tipo de retorno

int

property quantum_instance

Returns quantum instance.

Tipo de retorno

Optional[QuantumInstance]

property random

Return a numpy random.

run(quantum_instance=None, **kwargs)

Execute the algorithm with selected backend.

Parâmetros
• quantum_instance (Union[QuantumInstance, Backend, BaseBackend, None]) – the experimental setting.

• kwargs (dict) – kwargs

Retorna

results of an algorithm.

Tipo de retorno

dict

Levanta

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

set_backend(backend, **kwargs)

Sets backend with configuration.

Tipo de retorno

None