BackendServer#

class BackendServer(run_func, ip_address=None, port=None)[source]#

This class allows convenient setup of a server respecting the Qunicorn interface.

Parameters:
run_funcfunction

A function that receives a QuantumCircuit, an integer specifying the amount of shots and a token in the form of a string. It returns the counts as a dictionary of bitstrings.

ip_addressstr, optional

The IP address of where the listening socket should be opened. By default, the IP address of the hosting machine will be used.

portint, optional

The port on which to listen for requests. By default, 9010 will be used.

is_simulatorbool, optional

A bool specifying whether the results returned by this server are due to a simulator. The default is True.

Examples

We create a server listening on the localhost IP address using a run function which prints the token and queries the Aer-simulator.

def run_func(qasm_str, shots):

    from qiskit import QuantumCircuit
    #Convert to qiskit

    qiskit_qc = QuantumCircuit.from_qasm_str(qasm_str)

    from qiskit_aer import AerSimulator
    qiskit_backend = AerSimulator()

    #Run Circuit on the Qiskit backend
    return qiskit_backend.run(qiskit_qc, shots = shots).result().get_counts()

from qrisp.interface import BackendServer
example_server = BackendServer(run_func, ip_address = "127.0.0.1", port = 8080)
example_server.start()

Methods#