Esempio n. 1
0
    def test_store_credentials_overwrite(self):
        """Test overwriting qiskitrc credentials."""
        credentials = Credentials('QISKITRC_TOKEN', url=QE_URL, hub='HUB')
        credentials2 = Credentials('QISKITRC_TOKEN_2', url=QE_URL)

        with custom_qiskitrc():
            store_credentials(credentials)
            # Cause all warnings to always be triggered.
            warnings.simplefilter("always")
            # Attempt overwriting.
            with warnings.catch_warnings(record=True) as w:
                store_credentials(credentials)
                self.assertIn('already present', str(w[0]))

            with no_file('Qconfig.py'), no_envs(
                    CREDENTIAL_ENV_VARS), mock_ibmq_provider():
                # Attempt overwriting.
                store_credentials(credentials2, overwrite=True)
                IBMQ.load_accounts()

        # Ensure that the credentials are the overwritten ones - note that the
        # 'hub' parameter was removed.
        self.assertEqual(len(IBMQ._accounts), 1)
        self.assertEqual(
            list(IBMQ._accounts.values())[0].credentials.token,
            'QISKITRC_TOKEN_2')
    def test_autoregister_no_credentials(self):
        """Test register() with no credentials available."""
        with no_file('Qconfig.py'), custom_qiskitrc(), no_envs():
            with self.assertRaises(IBMQAccountError) as context_manager:
                IBMQ.load_accounts()

        self.assertIn('No IBMQ credentials found', str(context_manager.exception))
Esempio n. 3
0
from qiskit.providers.ibmq import IBMQ
from Qconfig import APItoken
"""
Set your API Token.
You can get it from https://quantumexperience.ng.bluemix.net/qx/account,
looking for "Personal Access Token" section.
"""
QX_TOKEN = APItoken
"""
Authenticate with the IBM Q API in order to use online devices.
You need the API Token.
The account information is need to be stored locally on disk only once.
To store account information locally on disk, uncomment the next line.
"""
# print("Storing account information locally on disk ...")
# IBMQ.save_account(QX_TOKEN)

# The next line is mandatory to load the account infos stored
print("\nLoading account ...")
IBMQ.load_accounts()
# print_dict(IBMQ.stored_accounts()[0])
"""
Selecting backend of available devices.
"""
print("\nGetting backend ...")
backend_ibmq = IBMQ.get_backend('ibmqx2')
"""
Canceling job by id
"""
backend_ibmq.retrieve_job('5bd3a2154df859003d31ad0c').cancel()