Beispiel #1
0
 def test_shor_no_factors(self, n_v):
     """shor no factors test"""
     backend = Aer.get_backend("qasm_simulator")
     shor = Shor(quantum_instance=QuantumInstance(backend, shots=1000))
     result = shor.factor(N=n_v)
     self.assertTrue(result.factors == [])
     self.assertTrue(result.successful_counts == 0)
Beispiel #2
0
 def test_shor_factoring(self, n_v, backend, factors):
     """shor factoring test"""
     shor = Shor(quantum_instance=QuantumInstance(Aer.get_backend(backend),
                                                  shots=1000))
     result = shor.factor(N=n_v)
     self.assertListEqual(result.factors[0], factors)
     self.assertTrue(result.total_counts >= result.successful_counts)
Beispiel #3
0
 def test_shor_power(self, base, power):
     """shor power test"""
     n_v = int(math.pow(base, power))
     backend = Aer.get_backend("qasm_simulator")
     shor = Shor(quantum_instance=QuantumInstance(backend, shots=1000))
     result = shor.factor(N=n_v)
     self.assertTrue(result.factors == [base])
     self.assertTrue(result.total_counts >= result.successful_counts)
Beispiel #4
0
 def test_shor_no_factors(self, n_v):
     """ shor no factors test """
     shor = Shor(n_v)
     backend = BasicAer.get_backend('qasm_simulator')
     quantum_instance = QuantumInstance(backend, shots=1000)
     ret = shor.run(quantum_instance)
     self.assertTrue(ret['factors'] == [])
     self.assertTrue(ret["successful_counts"] == 0)
Beispiel #5
0
 def test_shor_factoring(self, n_v, backend, factors):
     """ shor factoring test """
     shor = Shor(n_v)
     result_dict = shor.run(
         QuantumInstance(BasicAer.get_backend(backend), shots=1000))
     self.assertListEqual(result_dict['factors'][0], factors)
     self.assertTrue(
         result_dict["total_counts"] >= result_dict["successful_counts"])
Beispiel #6
0
 def test_shor_power(self, base, power):
     """ shor power test """
     n_v = int(math.pow(base, power))
     shor = Shor(n_v)
     backend = BasicAer.get_backend('qasm_simulator')
     quantum_instance = QuantumInstance(backend, shots=1000)
     ret = shor.run(quantum_instance)
     self.assertTrue(ret['factors'] == [base])
     self.assertTrue(ret["total_counts"] >= ret["successful_counts"])
 def test_shor_factoring(self):
     """shor factoring test"""
     n_v = 15
     factors = [3, 5]
     qasm_simulator = QuantumInstance(
         self._qasm, shots=1000, seed_simulator=self.seed, seed_transpiler=self.seed
     )
     shor = Shor(quantum_instance=qasm_simulator)
     result = shor.factor(N=n_v)
     self.assertListEqual(result.factors[0], factors)
     self.assertTrue(result.total_counts >= result.successful_counts)
Beispiel #8
0
# Code blocks for qiskit notebook

## Block 1 - Setup
import math
import numpy as np
from qiskit import Aer
from qiskit.utils import QuantumInstance
from qiskit.algorithms import Shor


## Block 2 - Run 
N = 15
backend = Aer.get_backend('aer_simulator')
quantum_instance = QuantumInstance(backend, shots=1024)
shor = Shor(quantum_instance=quantum_instance)
result = shor.factor(N)
print(f"The list of factors of {N} as computed by the Shor's algorithm is {result.factors[0]}.")

## Block 3 - Eval Perf
print(f'Computed of qubits for circuit: {4 * math.ceil(math.log(N, 2)) + 2}')
print(f'Actual number of qubits of circuit: {shor.construct_circuit(N).num_qubits}')

## Block 4 - Version Info
import qiskit.tools.jupyter
%qiskit_version_table
%qiskit_copyright
Beispiel #9
0
 def test_shor_bad_input(self, n_v):
     """shor bad input test"""
     with self.assertRaises(ValueError):
         _ = Shor().factor(N=n_v)
Beispiel #10
0
 def test_shor_bad_input(self, n_v):
     """ shor bad input test """
     with self.assertRaises(ValueError):
         Shor(n_v)
 def setUp(self):
     super().setUp()
     backend = Aer.get_backend("qasm_simulator")
     self.instance = Shor(
         quantum_instance=QuantumInstance(backend, shots=1000))