Exemplo n.º 1
0
    def __init__(self, api: QuantumInspireAPI, provider: Any,
                 configuration: Optional[QasmBackendConfiguration] = None) -> None:
        """ Python implementation of a quantum simulator using Quantum Inspire API.

        Args:
            api: The interface instance to the Quantum Inspire API.
            provider: Provider for this backend.
            configuration: The configuration of the quantum inspire backend. The
                configuration must implement the fields given by the QiSimulatorPy.DEFAULT_CONFIGURATION. All
                configuration fields are listed in the table below. The table rows with an asterisk specify fields which
                can have a custom value and are allowed to be changed according to the description column.

                | key                     | description
                |-------------------------|----------------------------------------------------------------------------
                | backend_name (str)*     | The name of the quantum inspire backend. The API can list the name of each
                |                         | available backend using the function api.list_backend_types(). One of the
                |                         | listed names must be used.
                | backend_version (str)   | Backend version in the form X.Y.Z.
                | n_qubits (int)          | Number of qubits.
                | basis_gates (list[str]) | A list of basis gates to compile to.
                | gates (GateConfig)      | List of basis gates on the backend. Not used.
                | local (bool)            | Indicates whether the system is running locally or remotely. Not used.
                | simulator (bool)        | Specifies whether the backend is a simulator or a quantum system. Not used.
                | conditional (bool)      | Backend supports conditional operations.
                | open_pulse (bool)       | Backend supports open pulse. False.
                | memory (bool)           | Backend supports memory. True.
                | max_shots (int)         | Maximum number of shots supported.
                | max_experiments (int)   | Optional: Maximum number of experiments (circuits) per job.
        """
        super().__init__(configuration=(configuration or
                                        QuantumInspireBackend.DEFAULT_CONFIGURATION),
                         provider=provider)
        self.__backend: Dict[str, Any] = api.get_backend_type_by_name(self.name())
        self.__api: QuantumInspireAPI = api
Exemplo n.º 2
0
    def __init__(self, api: QuantumInspireAPI, provider: Any,
                 configuration: Optional[QasmBackendConfiguration] = None) -> None:
        """ Python implementation of a quantum simulator using Quantum Inspire API.

        :param api: The interface instance to the Quantum Inspire API.
        :param provider: Provider for this backend.
        :param configuration: The configuration of the Quantum Inspire backend. The
                configuration must implement the fields given by the QiSimulatorPy.DEFAULT_CONFIGURATION. All
                configuration fields are listed in the table below. The table rows with an asterisk specify fields which
                can have a custom value and are allowed to be changed according to the description column.

                =================== ============= =====================================================================
                Key                 Type          Description
                =================== ============= =====================================================================
                ``backend_name`` *  str           The name of the Quantum Inspire backend. The API can list the name of
                                                  each available backend using the function api.list_backend_types().
                                                  One of the listed names must be used.
                ``backend_version`` str           Backend version in the form X.Y.Z.
                ``n_qubits``        int           Number of qubits.
                ``basis_gates``     list[str]     A list of basis gates to compile to.
                ``gates``           GateConfig    List of basis gates on the backend. Not used.
                ``local``           bool          Indicates whether the system is running locally or remotely.
                ``simulator``       bool          Specifies whether the backend is a simulator or a quantum system.
                ``conditional``     bool          Backend supports conditional operations.
                ``open_pulse``      bool          Backend supports open pulse. False.
                ``memory``          bool          Backend supports memory. True.
                ``max_shots``       int           Maximum number of shots supported.
                ``max_experiments`` int           Optional: Maximum number of experiments (circuits) per job.
                ``coupling_map``    list[list]    Define the edges.
                =================== ============= =====================================================================
        """
        super().__init__(configuration=(configuration or
                                        QuantumInspireBackend.DEFAULT_CONFIGURATION),
                         provider=provider)
        self.__backend: Dict[str, Any] = api.get_backend_type_by_name(self.name())
        self.__api: QuantumInspireAPI = api
Exemplo n.º 3
0
                                    qubits,
                                    unitary,
                                    extra_empty_bits=extra_empty_bits,
                                    custom_prepare=custom_prepare)

    final_qasm = optimize(final_qasm, nancillas, qubits, extra_empty_bits)

    if topology is not None:
        final_qasm = map_to_topology(topology, final_qasm)

    final_qasm = optimize(final_qasm, nancillas, qubits, extra_empty_bits)

    if error_toggle:
        final_qasm = introduce_error(final_qasm, mu, sigma)

    final_qasm = optimize(final_qasm, nancillas, qubits, extra_empty_bits)

    backend_type = qi.get_backend_type_by_name('QX single-node simulator')
    result = qi.execute_qasm(final_qasm,
                             backend_type=backend_type,
                             number_of_shots=shots)

    # Classical postprocessing
    fraction, error = print_result(
        remove_degeneracy(result['histogram'], nancillas),
        desired_bit_accuracy, nancillas)

    print('Fraction: ', fraction)
    print('Error: ', error)
    print('Correct chance: ', 1 - (1 - p_succes)**shots)
def testErrorCorrection():
    server_url = r'https://api.quantum-inspire.com'
    print('Enter mail address')
    email = input()

    print('Enter password')
    password = getpass()
    auth = (email, password)

    qi = QuantumInspireAPI(server_url, auth)
    backend = qi.get_backend_type_by_name('QX single-node simulator')

    inputValues = [
        {
            'theta': 0,
            'phi': 0
        },  #|0>
        {
            'theta': np.pi,
            'phi': np.pi
        },  #|1>
        {
            'theta': np.pi / 2,
            'phi': np.pi / 2
        }  #|+>
    ]

    for inputValue in inputValues:
        print("Using input value " + str(inputValue))
        allErrorIdxs = []
        for nrOfErrors in range(2):
            allErrorIdxs += itertools.combinations(range(nbqubits), nrOfErrors)
        # iterate over all possible combinations of errors

        for errorIdxs in allErrorIdxs:
            inputStateComplex = _stateForInput(inputValue['theta'],
                                               inputValue['phi'])

            print("Introducing errors, indices " + str(errorIdxs))
            QASM = createProgram(inputValue, errorIdxs)

            prob_0 = 0
            prob_1 = 0

            if 1:  # Wavefunction
                result = qi.execute_qasm(QASM,
                                         backend_type=backend,
                                         number_of_shots=1)
            else:  # Do measurements
                result = qi.execute_qasm(QASM,
                                         backend_type=backend,
                                         number_of_shots=10)

            result = result['histogram']
            for key, value in zip(result.keys(), result.values()):
                if (int(key) % 2) == 0:  #Number is odd
                    prob_0 += value
                else:
                    prob_1 += value

            if abs(prob_0 - abs(inputStateComplex[0])**2) < 0.0001 and abs(
                    prob_1 - abs(inputStateComplex[1])**2) < 0.0001:
                print("Error correction works")
            else:
                print("Error correction fails")