BackendServer#
- class BackendServer(run_func, socket_ip_address=None, port=None, transport=None, name='generic_quantum_backend_server', ping_func=None, online_status=True)[source]#
This class allows convenient setup of a server respecting the Qrisp 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.
- socket_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, 9090 will be used.
- namestr, optional
A name for the server. The default is “generic_quantum_backend_server”.
- ping_funcfunction, optional
A function returning a BackendStatus object. The default is None.
- online_statusbool, optional
A bool specifying whether the server should be able to handle requests directly after startup. 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 QASM-simulator.
def run_func(qc, shots, token): #Convert to qiskit from qrisp.interface.circuit_converter import convert_circuit qiskit_qc = convert_circuit(qc, "qiskit") print(token) from qiskit import Aer qiskit_backend = Aer.get_backend('qasm_simulator') #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, socket_ip_address = "127.0.0.1", port = 8080) example_server.start()
Methods#
Starts the server. |
|
Stops the server. |