def test_get_token_authentication(self): secret_token = 'secret' auth = get_token_authentication(secret_token) # TokenAuthentication doesn't have __equal__ implemented, so check fields self.assertEqual(auth.token, secret_token) self.assertEqual(auth.scheme, 'token') with patch.dict('os.environ', values={'QI_TOKEN': secret_token}): auth = get_token_authentication() self.assertEqual(auth.token, secret_token) self.assertEqual(auth.scheme, 'token')
def test_get_token_authentication(self): secret_token = 'secret' auth = get_token_authentication(secret_token) # TokenAuthentication doesn't have __equal__ implemented, so check fields self.assertEqual(auth.token, secret_token) self.assertEqual(auth.scheme, 'token') os.environ.get = MagicMock() os.environ.get.return_value = secret_token auth = get_token_authentication() self.assertEqual(auth.token, secret_token) self.assertEqual(auth.scheme, 'token')
def set_token_authentication(self, token: str, qi_url: str = QI_URL) -> None: """ Set up token authentication for Quantum Inspire. Args: token: A valid token. qi_url: URL that points to quantum-inspire api. Default value: 'https://api.quantum-inspire.com'. """ authentication = get_token_authentication(token) self.set_authentication(authentication, qi_url)
def get_authentication_alt(): """ Gets the authentication for connecting to the Quantum Inspire API.""" token = load_account() if token is not None: return get_token_authentication(token) else: print('Enter email:') email = input() print('Enter password') password = getpass() return get_basic_authentication(email, password)
def get_authentication(qi_email=None, qi_password=None, token=None): """ Gets the authentication for connecting to the Quantum Inspire API.""" if token is not None: return get_token_authentication(token) else: if qi_email is None or qi_password is None: print('Enter email') email = input() print('Enter password') password = getpass() else: email, password = qi_email, qi_password return get_basic_authentication(email, password)
def get_authentication(): """ Gets the authentication for connecting to the Quantum Inspire API.""" token = load_token() if token is not None: return get_token_authentication(token) else: if QI_EMAIL is None or QI_PASSWORD is None: print('Enter email:') email = input() print('Enter password') password = getpass() else: email, password = QI_EMAIL, QI_PASSWORD return get_basic_authentication(email, password)
def get_authentication(B): if B == 'QI': """ Gets the authentication for connecting to the Quantum Inspire API.""" token = load_account() if token is not None: return get_token_authentication(token) else: if QI_EMAIL is None or QI_PASSWORD is None: print('Enter email:') email = input() print('Enter password') password = getpass() else: email, password = QI_EMAIL, QI_PASSWORD return get_basic_authentication(email, password) elif B == 'IBMQ': print('Enter IBMQ token:') ibmq_token = input() return IBMQ.enable_account(ibmq_token)
def setup_tabs(self): _translate = QtCore.QCoreApplication.translate self.ibm_backends = None self.dwave_backends = None self.inspire_backends = None self.rigetti_backends = None self.tab_infos = [] # backend1 = {'name': '9q-square-noisy-qvm', 'number_of_qubits': 9, # 'max_number_of_shots': 65536, 'max_experiments': 'unlimited', # 'description': 'v. 1.17', 'accuracy': 'not accurate', # 'remaining_jobs': 'unlimited'} # backend2 = {'name': '26q-qvm', 'number_of_qubits': 26, # 'max_number_of_shots': 65536, 'max_experiments': 'unlimited', # 'description': 'v. 1.17', 'accuracy': '0', # 'remaining_jobs': 'unlimited'} # self.rigetti_backends = [backend1, backend2] if self.__qiskit is not None: IBMQ.enable_account(self.__qiskit) ibm_provider = IBMQ.get_provider('ibm-q') self.ibm_backends = ibm_provider.backends() if self.__inspire is not None: enable_account(self.__inspire) QI.set_authentication() server_url = r'https://api.quantum-inspire.com' auth = get_token_authentication() self.qi = QuantumInspireAPI(server_url, auth) # backends = [] # for back in self.qi.get_backend_types(): # current_backend = {'name': back.get('name'), 'number_of_qubits': back.get('number_of_qubits'), # 'max_number_of_shots': back.get('max_number_of_shots'), # 'max_experiments': back.get('max_number_of_simultaneous_jobs'), # 'description': back.get('description'), 'accuracy': 'not measured', # 'remaining_jobs': back.get('max_number_of_simultaneous_jobs')} # backends.append(current_backend) self.inspire_backends = self.qi.get_backend_types() if self.ibm_backends is not None: for backend in self.ibm_backends: self.tab_infos.append(ComputerInfoTab(backend)) # if self.inspire_backends is not None: # for backend in self.inspire_backends: # # server = r'https://api.quantum-inspire.com' # # email = '*****@*****.**' # # password = '******' # # auth = HTTPBasicAuth(email, password) # # # # result = requests.get(f'{server}/projects', auth=auth) # # # # print(f'result status: {result.status_code}') # # print(result.json()) # # server = r'https://api.quantum-inspire.com' # # auth = coreapi.auth.TokenAuthentication(self.__inspire) # # client = coreapi.Client(auth=auth) # # content = client.get(f'{server}/backendtypes/1/calibration') # # print(content) # # action = ['projects', 'list'] # # result = client.action(schema, action) # # print(result) # # server = r'https://api.quantum-inspire.com' # # email = '*****@*****.**' # # password = '******' # # auth = HTTPBasicAuth(email, password) # # contents = urllib.request.urlopen(r'https://api.quantum-inspire.com/backendtypes/1/calibration/',).read() # self.tab_infos.append(ComputerInfoTab(backend._QuantumInspireBackend__backend)) if self.inspire_backends is not None: for backend in self.inspire_backends: self.tab_infos.append(ComputerInfoTab(backend)) if self.rigetti_backends is not None: for backend in self.rigetti_backends: self.tab_infos.append(ComputerInfoTab(backend)) self.tab_widget = QtWidgets.QTabWidget(self.central_widget) self.tab_widget.setObjectName("tabWidget") self.tab_widget.addTab(self.test_info_tab.tab, "") self.tab_widget.setTabText( self.tab_widget.indexOf(self.test_info_tab.tab), _translate('main_window', self.test_info_tab.name)) self.tab_widget.addTab(self.results_info_tab.tab, "") self.tab_widget.setTabText( self.tab_widget.indexOf(self.results_info_tab.tab), _translate('main_window', self.results_info_tab.name)) for tab_info in self.tab_infos: self.tab_widget.addTab(tab_info.tab, "") self.tab_widget.setTabText( self.tab_widget.indexOf(tab_info.tab), _translate("main_window", tab_info.tab.objectName())) self.gridLayout_2.addWidget(self.tab_widget, 0, 0, 1, 1) self.tab_widget.setCurrentIndex(0)
def test_get_token_authentication(self): secret_token = 'secret' auth = get_token_authentication(secret_token) # TokenAuthentication doesn't have __equal__ implemented, so check fields self.assertEqual(auth.token, secret_token) self.assertEqual(auth.scheme, 'token')
def get_authentication(): """ Gets the authentication for connecting to the Quantum Inspire API.""" token = os.getenv('QI_TOKEN') if token is not None: return get_token_authentication(token) return None