How to use the quantuminspire.exceptions.ApiError 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 / api.py View on Github external
|-------------------------------|----------------------------------------------------------------------
                | url (str)                     | The url for this project.
                | id (int)                      | Unique id of the project.
                | name (str)                    | Name of the project.
                | owner (int)                   | Url to get the owner of the project.
                | assets (str)                  | Url to get the assets of the project.
                | backend_type (str)            | Url to get the backend type of the project.
                | default_number_of_shots (int) | Default number of executions for this project.
                | created (str)                 | Date/time when the project was created.
                | number_of_jobs (int)          | Number of jobs managed within this project.
                | last_saved (str)              | Date/time when the project was saved.
        """
        try:
            project = self._action(['projects', 'read'], params={'id': project_id})
        except ErrorMessage as err_msg:
            raise ApiError(f'Project with id {project_id} does not exist!') from err_msg
        return OrderedDict(project)
github QuTech-Delft / quantuminspire / src / quantuminspire / qiskit / quantum_inspire_provider.py View on Github external
def backends(self, name: Optional[str] = None, **kwargs: Any) -> List[QuantumInspireBackend]:
        """
        Provides a list of backends.

        Args:
            name: Name of the requested backend.
            **kwargs: Used for filtering, not implemented.

        Returns:
            List of backends that meet the filter requirements.
        """
        if self._api is None:
            raise ApiError('Authentication details have not been set.')

        available_backends = self._api.get_backend_types()
        if name is not None:
            available_backends = list(filter(lambda b: b['name'] == name, available_backends))
        backends = []
        for backend in available_backends:
            if backend['is_allowed']:
                config = copy(QuantumInspireBackend.DEFAULT_CONFIGURATION)
                self._adjust_backend_configuration(config, backend)
                backends.append(QuantumInspireBackend(self._api, provider=self, configuration=config))

        return backends
github QuTech-Delft / quantuminspire / src / quantuminspire / qiskit / circuit_parser.py View on Github external
stream: The string-io stream to where the resulting cQASM is written.
            instruction: The Qiskit instruction to translate to cQASM.

        """
        conditional_reg_idx = instruction.conditional
        conditional = next((x for x in self.bfunc_instructions if x.register == conditional_reg_idx), None)
        if conditional is None:
            raise ApiError(f'Conditional not found: reg_idx = {conditional_reg_idx}')
        self.bfunc_instructions.remove(conditional)

        conditional_type = conditional.relation
        if conditional_type != '==':
            raise ApiError(f'Conditional statement with relation {conditional_type} not supported')
        mask = int(conditional.mask, 16)
        if mask == 0:
            raise ApiError(f'Conditional statement {instruction.name.lower()} without a mask')
        lowest_mask_bit, mask_length = self.get_mask_data(mask)
        val = int(conditional.val, 16)
        masked_val = mask & val

        # form the negation to the 0-values of the measurement registers, when value == mask no bits are negated
        negate_zeroes_line = ''
        if masked_val != mask:
            negate_zeroes_line = 'not b[' + ','.join(
                str(i) for i in range(lowest_mask_bit, lowest_mask_bit + mask_length)
                if not (masked_val & (1 << i))) + ']\n'

        if mask_length == 1:
            binary_control = f'b[{lowest_mask_bit}], '
        else:
            # form multi bits control - qasm-single-gate-multiple-qubits
            binary_control = f'b[{lowest_mask_bit}:{lowest_mask_bit + mask_length - 1}], '
github QuTech-Delft / quantuminspire / src / quantuminspire / api.py View on Github external
| backend (str)                 | Url to get the backend the job is executed on.
                | backend_type (str)            | Url to get the backend type of the backend the job is executed on.
                | results (str)                 | Url to get the results for the job.
                | queued_at (str)               | The date-time the job is queued at.
                |                               | The format is 'yyyy-MM-ddTHH:mm:ss.SSSSSSZ' Zulu Time.
                | number_of_shots (int)         | Number of executions for this job.
                | full_state_projection (bool)  | Indicates if the backend uses full state projection to determine
                |                               | the quantum state.
                |                               | Used for optimizing simulations. For more information see:
                |                               | https://www.quantum-inspire.com/kbase/optimization-of-simulations/
                | user_data (str)               | The user configuration data.
        """
        try:
            job = self._action(['jobs', 'read'], params={'id': job_id})
        except ErrorMessage as err_msg:
            raise ApiError(f'Job with id {job_id} does not exist!') from err_msg
        return OrderedDict(job)
github QuTech-Delft / quantuminspire / src / quantuminspire / api.py View on Github external
""" Gets the properties of a backend type, given the backend name (case insensitive).

        Args:
            backend_name: The backend name.

        Raises:
            ApiError: An ApiError exception is thrown when the backend name does not exist.

        Returns:
            The properties of the backend type of the specific backend.
            See `get_default_backend_type` for a description of the backend type properties.
        """
        backend_type = next((backend for backend in self.get_backend_types()
                            if backend['name'].lower() == backend_name.lower()), None)
        if backend_type is None:
            raise ApiError(f'Backend type with name {backend_name} does not exist!')
        return OrderedDict(backend_type)
github QuTech-Delft / quantuminspire / src / quantuminspire / api.py View on Github external
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
github QuTech-Delft / quantuminspire / src / quantuminspire / api.py View on Github external
|---------------------------|---------------------------------------------------------------------------
                | url (str)                 | The url to get this asset.
                | id (int)                  | Unique id of this asset.
                | name (str)                | The name to get the asset.
                | contentType (str)         | The description of the content e.g. 'application/qasm' or
                |                           | 'text/plain'.
                | content (str)             | The content itself. For example a cQASM program when linked to a job.
                | measurement_mask (int)    | A mask for the measured bits in the cQASM program. The measurement_mask
                |                           | is calculated when the asset is assigned to a job.
                | project (str)             | Url to get the project properties for which this asset was created.
                | project_id (int)          | The project id of the project for which this asset was created.
        """
        try:
            asset = self._action(['assets', 'read'], params={'id': asset_id})
        except ErrorMessage as err_msg:
            raise ApiError(f'Asset with id {asset_id} does not exist!') from err_msg
        return OrderedDict(asset)
github QuTech-Delft / quantuminspire / src / quantuminspire / api.py View on Github external
""" Deletes the project identified by project_id together with all its assets, jobs and results.
            Only projects can be deleted that are registered for the user the API is currently authenticated for.

        Args:
            project_id: The project identification number.

        Raises:
            ApiError: If the project identified by project_id does not exist.
        """
        payload = {
            'id': project_id
        }
        try:
            self._action(['projects', 'delete'], params=payload)
        except ErrorMessage as err_msg:
            raise ApiError(f'Project with id {project_id} does not exist!') from err_msg