0
$\begingroup$

I have tried to run Shor's algorithm using IBM high performance simulator. I am currently using QuantumInstance to factorize a number. The code is provided below:

from qiskit import *

IBMQ.save_account('<My API String>')
IBMQ.load_account()

from qiskit.tools.monitor import job_monitor
from qiskit.utils import QuantumInstance
from qiskit.algorithms import Shor

N=63
provider = IBMQ.get_provider('ibm-q')
sim = provider.backends.ibmq_qasm_simulator
quantum_instance = QuantumInstance(sim, shots=1024)
shor = Shor(quantum_instance=quantum_instance)
job_monitor(shor, interval=2)
rslt = shor.factor(N)
hsl = rslt.factors[0]
print("Factor result: "+str(hsl))

And it is giving me this error:

configrc.store_credentials:WARNING:2022-04-18 13:49:09,225: Credentials already present. Set overwrite=True to overwrite.
Traceback (most recent call last):
  File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python310\lib\site-packages\qiskit\providers\ibmq\api\session.py", line 278, in request
    response.raise_for_status()
  File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\models.py", line 960, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://auth.quantum-computing.ibm.com/api/users/loginWithToken

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "D:\Python\test_shor_2_cloud.py", line 4, in <module>
    IBMQ.load_account()
  File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python310\lib\site-packages\qiskit\providers\ibmq\ibmqfactory.py", line 191, in load_account
    self._initialize_providers(credentials, preferences)
  File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python310\lib\site-packages\qiskit\providers\ibmq\ibmqfactory.py", line 456, in _initialize_providers
    auth_client = AuthClient(credentials.token,
  File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python310\lib\site-packages\qiskit\providers\ibmq\api\clients\auth.py", line 41, in __init__
    self.base_api = self._init_service_clients(**request_kwargs)
  File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python310\lib\site-packages\qiskit\providers\ibmq\api\clients\auth.py", line 53, in _init_service_clients     
    access_token = self._request_access_token()
  File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python310\lib\site-packages\qiskit\providers\ibmq\api\clients\auth.py", line 75, in _request_access_token     
    response = self.auth_api.login(self.api_token)
  File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python310\lib\site-packages\qiskit\providers\ibmq\api\rest\root.py", line 125, in login
    return self.session.post(url, json={'apiToken': api_token}).json()
  File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\sessions.py", line 577, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python310\lib\site-packages\qiskit\providers\ibmq\api\session.py", line 300, in request
    raise RequestsApiError(message, status_code) from ex
qiskit.providers.ibmq.api.exceptions.RequestsApiError: '401 Client Error: Unauthorized for url: https://auth.quantum-computing.ibm.com/api/users/loginWithToken. Login failed., Error code: 3446.'

Any suggestion?

$\endgroup$
2
  • $\begingroup$ You can check those 2 posts, the issue looks similar to them 1 and 2 $\endgroup$
    – KMagdy
    Apr 18 at 8:26
  • $\begingroup$ Ahhh it's seems I don't force my save my API code... thanks for the links $\endgroup$
    – AFOEK
    Apr 19 at 6:17

1 Answer 1

1
$\begingroup$

You can run it on IBM circuit runner.Just execute the following code with your circuit.

    from qiskit import IBMQ

options = {
    'backend_name': 'ibmq_qasm_simulator'
}

runtime_inputs = {
    # A circuit or a list
  # of QuantumCircuits.
  'circuits': None, # [object,array] (required)
    
    # Whether to reset the qubits
  # to the ground state for
  # each shot.
  'init_qubits': None, # boolean
    
    # Initial position of virtual qubits
  # on physical qubits.
  'initial_layout': None, # [object,array]
    
    # Name of layout selection pass
  # ('trivial', 'dense', 'noise_adaptive', 'sabre')
  'layout_method': None, # string
    
    # Whether to apply measurement error
  # mitigation. Default is False.
  'measurement_error_mitigation': None, # boolean
    
    # How much optimization to perform
  # on the circuits (0-3). Higher
  # levels generate more optimized circuits.
  # Default is 1.
  'optimization_level': None, # integer
    
    # Delay between programs in seconds.
  'rep_delay': None, # number
    
    # Name of routing pass ('basic',
  # 'lookahead', 'stochastic', 'sabre').
  'routing_method': None, # string
    
    # Sets random seed for the
  # stochastic parts of the transpiler.
  'seed_transpiler': None, # integer
    
    # Number of repetitions of each
  # circuit, for sampling. Default: 1024.
  'shots': None, # integer
    
    # Name of translation pass ('unroller',
  # 'translator', 'synthesis').
  'translation_method': None, # string
    
    # Additional compilation options.
  'transpiler_options': None # object
}

IBMQ.load_account()
provider = IBMQ.get_provider(
    hub='ibm-q',
    group='open',
    project='main'
)

job = provider.runtime.run(
    program_id='circuit-runner',
    options=options,
    inputs=runtime_inputs
)

# Job id
print(job.job_id())
# See job status
print(job.status())

# Get results
result = job.result()
$\endgroup$
1
  • $\begingroup$ it's seems I cannot use circuit runner since I don't initialize my circuit but I use QuantumInstance for may shor algorithm $\endgroup$
    – AFOEK
    Apr 19 at 6:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.