162 lines
6.1 KiB
Plaintext
162 lines
6.1 KiB
Plaintext
---
|
||
title: Shor
|
||
description: API reference for qiskit.aqua.algorithms.Shor
|
||
in_page_toc_min_heading_level: 1
|
||
python_api_type: class
|
||
python_api_name: qiskit.aqua.algorithms.Shor
|
||
---
|
||
|
||
<span id="qiskit-aqua-algorithms-shor" />
|
||
|
||
# qiskit.aqua.algorithms.Shor
|
||
|
||
<Class id="qiskit.aqua.algorithms.Shor" isDedicatedPage={true} github="https://github.com/qiskit-community/qiskit-aqua/tree/stable/0.8/qiskit/aqua/algorithms/factorizers/shor.py" signature="Shor(N=15, a=2, quantum_instance=None)" modifiers="class">
|
||
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$ .
|
||
|
||
Adapted from [https://github.com/ttlion/ShorAlgQiskit](https://github.com/ttlion/ShorAlgQiskit)
|
||
|
||
See also [https://arxiv.org/abs/quant-ph/0205095](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\_\_
|
||
|
||
<Function id="qiskit.aqua.algorithms.Shor.__init__" signature="__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
|
||
</Function>
|
||
|
||
## Methods
|
||
|
||
| | |
|
||
| ------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------ |
|
||
| [`__init__`](#qiskit.aqua.algorithms.Shor.__init__ "qiskit.aqua.algorithms.Shor.__init__")(\[N, a, quantum\_instance]) | **type N**`int` |
|
||
| [`construct_circuit`](#qiskit.aqua.algorithms.Shor.construct_circuit "qiskit.aqua.algorithms.Shor.construct_circuit")(\[measurement]) | Construct circuit. |
|
||
| [`modinv`](#qiskit.aqua.algorithms.Shor.modinv "qiskit.aqua.algorithms.Shor.modinv")(a, m) | Returns the modular multiplicative inverse of a with respect to the modulus m. |
|
||
| [`run`](#qiskit.aqua.algorithms.Shor.run "qiskit.aqua.algorithms.Shor.run")(\[quantum\_instance]) | Execute the algorithm with selected backend. |
|
||
| [`set_backend`](#qiskit.aqua.algorithms.Shor.set_backend "qiskit.aqua.algorithms.Shor.set_backend")(backend, \*\*kwargs) | Sets backend with configuration. |
|
||
|
||
## Attributes
|
||
|
||
| | |
|
||
| ------------------------------------------------------------------------------------------------------------------ | ------------------------- |
|
||
| [`backend`](#qiskit.aqua.algorithms.Shor.backend "qiskit.aqua.algorithms.Shor.backend") | Returns backend. |
|
||
| [`quantum_instance`](#qiskit.aqua.algorithms.Shor.quantum_instance "qiskit.aqua.algorithms.Shor.quantum_instance") | Returns quantum instance. |
|
||
| [`random`](#qiskit.aqua.algorithms.Shor.random "qiskit.aqua.algorithms.Shor.random") | Return a numpy random. |
|
||
|
||
### backend
|
||
|
||
<Attribute id="qiskit.aqua.algorithms.Shor.backend">
|
||
Returns backend.
|
||
|
||
**Return type**
|
||
|
||
`Union`\[`Backend`, `BaseBackend`]
|
||
</Attribute>
|
||
|
||
### construct\_circuit
|
||
|
||
<Function id="qiskit.aqua.algorithms.Shor.construct_circuit" signature="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.
|
||
</Function>
|
||
|
||
### modinv
|
||
|
||
<Function id="qiskit.aqua.algorithms.Shor.modinv" signature="modinv(a, m)" modifiers="static">
|
||
Returns the modular multiplicative inverse of a with respect to the modulus m.
|
||
|
||
**Return type**
|
||
|
||
`int`
|
||
</Function>
|
||
|
||
### quantum\_instance
|
||
|
||
<Attribute id="qiskit.aqua.algorithms.Shor.quantum_instance">
|
||
Returns quantum instance.
|
||
|
||
**Return type**
|
||
|
||
`Optional`\[`QuantumInstance`]
|
||
</Attribute>
|
||
|
||
### random
|
||
|
||
<Attribute id="qiskit.aqua.algorithms.Shor.random">
|
||
Return a numpy random.
|
||
</Attribute>
|
||
|
||
### run
|
||
|
||
<Function id="qiskit.aqua.algorithms.Shor.run" signature="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**](qiskit.aqua.AquaError "qiskit.aqua.AquaError") – If a quantum instance or backend has not been provided
|
||
</Function>
|
||
|
||
### set\_backend
|
||
|
||
<Function id="qiskit.aqua.algorithms.Shor.set_backend" signature="set_backend(backend, **kwargs)">
|
||
Sets backend with configuration.
|
||
|
||
**Return type**
|
||
|
||
`None`
|
||
</Function>
|
||
</Class>
|
||
|