How to use the quantuminspire.exceptions.AuthenticationError function in quantuminspire

To help you get started, we’ve selected a few quantuminspire examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github QuTech-Delft / quantuminspire / src / quantuminspire / projectq / backend_qx.py View on Github external
BasicEngine.__init__(self)
        self._flushed: bool = False
        """ Because engines are meant to be 'single use' by the way ProjectQ is designed,
        any additional gates received after a FlushGate triggers an exception. """
        self._clear: bool = True
        self._reset()
        self._verbose: int = verbose
        self._cqasm: str = str()
        self._measured_states: Dict[int, float] = {}
        self._measured_ids: List[int] = []
        self._allocation_map: List[Tuple[int, int]] = []
        self._max_qubit_id: int = -1
        if quantum_inspire_api is None:
            try:
                quantum_inspire_api = QuantumInspireAPI()
            except AuthenticationError as ex:
                raise AuthenticationError('Make sure you have saved your token credentials on disk or '
                                          'provide a QuantumInspireAPI instance as parameter to QIBackend') from ex
        self._quantum_inspire_api: QuantumInspireAPI = quantum_inspire_api
        self._backend_type: Dict[str, Any] = self._quantum_inspire_api.get_backend_type(backend_type)
        if num_runs < 1 or num_runs > self._backend_type['max_number_of_shots']:
            raise ProjectQBackendError(f'Invalid number of runs (num_runs={num_runs})')
        self._num_runs: int = num_runs
        self._full_state_projection = not self._backend_type["is_hardware_backend"]
        self._is_simulation_backend = not self._backend_type["is_hardware_backend"]
        self._max_number_of_qubits: int = self._backend_type["number_of_qubits"]
        self._one_qubit_gates: Tuple[Any, ...] = self._get_one_qubit_gates()
        self._two_qubit_gates: Tuple[Any, ...] = self._get_two_qubit_gates()
        self._three_qubit_gates: Tuple[Any, ...] = self._get_three_qubit_gates()
github QuTech-Delft / quantuminspire / src / quantuminspire / projectq / backend_qx.py View on Github external
self._flushed: bool = False
        """ Because engines are meant to be 'single use' by the way ProjectQ is designed,
        any additional gates received after a FlushGate triggers an exception. """
        self._clear: bool = True
        self._reset()
        self._verbose: int = verbose
        self._cqasm: str = str()
        self._measured_states: Dict[int, float] = {}
        self._measured_ids: List[int] = []
        self._allocation_map: List[Tuple[int, int]] = []
        self._max_qubit_id: int = -1
        if quantum_inspire_api is None:
            try:
                quantum_inspire_api = QuantumInspireAPI()
            except AuthenticationError as ex:
                raise AuthenticationError('Make sure you have saved your token credentials on disk or '
                                          'provide a QuantumInspireAPI instance as parameter to QIBackend') from ex
        self._quantum_inspire_api: QuantumInspireAPI = quantum_inspire_api
        self._backend_type: Dict[str, Any] = self._quantum_inspire_api.get_backend_type(backend_type)
        if num_runs < 1 or num_runs > self._backend_type['max_number_of_shots']:
            raise ProjectQBackendError(f'Invalid number of runs (num_runs={num_runs})')
        self._num_runs: int = num_runs
        self._full_state_projection = not self._backend_type["is_hardware_backend"]
        self._is_simulation_backend = not self._backend_type["is_hardware_backend"]
        self._max_number_of_qubits: int = self._backend_type["number_of_qubits"]
        self._one_qubit_gates: Tuple[Any, ...] = self._get_one_qubit_gates()
        self._two_qubit_gates: Tuple[Any, ...] = self._get_two_qubit_gates()
        self._three_qubit_gates: Tuple[Any, ...] = self._get_three_qubit_gates()
github QuTech-Delft / quantuminspire / src / quantuminspire / api.py View on Github external
Note: When no project name is given, a temporary project is created for the job and deleted after the job
              has finished. When a project name is given, a project is created if it does not exist, but re-used
              if a project with that name already exists. In either case, the project will not be deleted when a
              project name is supplied here.

        Raises:
            AuthenticationError: An AuthenticationError exception is raised when no authentication is given
                                 and the token could not be loaded from the default location.
            ApiError: An ApiError exception is raised when the schema could not be loaded.
        """
        if authentication is None:
            token = load_account()
            if token is not None:
                authentication = TokenAuthentication(token, scheme="token")
            else:
                raise AuthenticationError('No credentials have been provided or found on disk')
        self.__client = coreapi_client_class(auth=authentication)
        self.project_name = project_name
        self.base_uri = base_uri
        self.enable_fsp_warning = True
        try:
            self._load_schema()
        except (CoreAPIException, TypeError) as ex:
            raise ApiError(f'Could not connect to {base_uri}') from ex