How to use quantuminspire - 10 common examples

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 / qiskit / backend_qx.py View on Github external
c = ClassicalRegister(4)
                circuit = QuantumCircuit(q, c)
                circuit.h(q[0]).c_if(c, 15)

                Because cQASM has the same number of classical registers as qubits (2 in this case),
                this circuit cannot be translated to valid cQASM.

        Args:
            experiment: The experiment with gate operations and header.

        Raises:
            QisKitBackendError: When the value is not correct.
        """
        number_of_clbits = experiment.header.memory_slots
        if number_of_clbits < 1:
            raise QisKitBackendError("Invalid amount of classical bits ({})!".format(number_of_clbits))

        if BaseBackend.configuration(self).conditional:
            number_of_qubits = experiment.header.n_qubits
            if number_of_clbits > number_of_qubits:
                # no problem when there are no conditional gate operations
                for instruction in experiment.instructions:
                    if hasattr(instruction, 'conditional'):
                        raise QisKitBackendError("Number of classical bits must be less than or equal to the"
                                                 " number of qubits when using conditional gate operations")
github QuTech-Delft / quantuminspire / docs / examples / example_qiskit_conditional.py View on Github external
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)


if __name__ == '__main__':

    authentication = get_authentication()
    QI.set_authentication(authentication, QI_URL)
    qi_backend = QI.get_backend('QX single-node simulator')

    q = QuantumRegister(3, "q")
    c0 = ClassicalRegister(1, "c0")
    c1 = ClassicalRegister(1, "c1")
    c2 = ClassicalRegister(1, "c2")
    qc = QuantumCircuit(q, c0, c1, c2, name="conditional")

    qc.h(q[0])
    qc.h(q[1]).c_if(c0, 0)  # h-gate on q[1] is executed
    qc.h(q[2]).c_if(c1, 1)  # h-gate on q[2] is not executed

    qc.measure(q[0], c0)
    qc.measure(q[1], c1)
    qc.measure(q[2], c2)

    qi_job = execute(qc, backend=qi_backend, shots=1024)
github QuTech-Delft / quantuminspire / docs / example_qiskit_entangle.py View on Github external
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)


if __name__ == '__main__':

    authentication = get_authentication()
    QI.set_authentication(authentication, QI_URL)
    qi_backend = QI.get_backend('QX single-node simulator')

    q = QuantumRegister(2)
    b = ClassicalRegister(2)
    circuit = QuantumCircuit(q, b)

    circuit.h(q[0])
    circuit.cx(q[0], q[1])
    circuit.measure(q, b)

    qi_job = execute(circuit, backend=qi_backend, shots=256)
    qi_result = qi_job.result()
    histogram = qi_result.get_counts(circuit)
    print('\nState\tCounts')
    [print('{0}\t\t{1}'.format(state, counts)) for state, counts in histogram.items()]
    # Print the full state probabilities histogram
github QuTech-Delft / quantuminspire / docs / examples / example_qiskit_conditional.py View on Github external
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)


if __name__ == '__main__':

    authentication = get_authentication()
    QI.set_authentication(authentication, QI_URL)
    qi_backend = QI.get_backend('QX single-node simulator')

    q = QuantumRegister(3, "q")
    c0 = ClassicalRegister(1, "c0")
    c1 = ClassicalRegister(1, "c1")
    c2 = ClassicalRegister(1, "c2")
    qc = QuantumCircuit(q, c0, c1, c2, name="conditional")

    qc.h(q[0])
    qc.h(q[1]).c_if(c0, 0)  # h-gate on q[1] is executed
    qc.h(q[2]).c_if(c1, 1)  # h-gate on q[2] is not executed

    qc.measure(q[0], c0)
    qc.measure(q[1], c1)
    qc.measure(q[2], c2)
github QuTech-Delft / quantuminspire / docs / example_qiskit_entangle.py View on Github external
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)


if __name__ == '__main__':

    authentication = get_authentication()
    QI.set_authentication(authentication, QI_URL)
    qi_backend = QI.get_backend('QX single-node simulator')

    q = QuantumRegister(2)
    b = ClassicalRegister(2)
    circuit = QuantumCircuit(q, b)

    circuit.h(q[0])
    circuit.cx(q[0], q[1])
    circuit.measure(q, b)

    qi_job = execute(circuit, backend=qi_backend, shots=256)
    qi_result = qi_job.result()
    histogram = qi_result.get_counts(circuit)
    print('\nState\tCounts')
    [print('{0}\t\t{1}'.format(state, counts)) for state, counts in histogram.items()]
    # Print the full state probabilities histogram
    probabilities_histogram = Obj.to_dict(qi_result.data(circuit)['probabilities'])
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)