qrisp.quantum_network.QuantumNetworkClient.run#

QuantumNetworkClient.run(qc, shots=None)[source]#

Runs a QuantumCircuit on the client’s backend. Note that QuantumNetwork simulations do not support multiple shots, as the quantum state of the network is stored and updated everytime a client sends a query. Multiple shots could yield differing measurement outcomes, which implies an ambiguous quantum state of the network. Nevertheless, the results are returned in the form of a dictionary in order to comply with the quantum circuit execution backend interface.

Note that it is possible to submit QuantumCircuits which contain qubits, that have not been requested previously. In this case, the qubits names are internally extended by the string “@client_name” (if they aren’t extended in this way already). This is to allow multiple clients to submit circuits with matching qubit names.

Parameters
qcQuantumCircuit

The QuantumCircuit to run.

Returns
resdict

A dictionary containing a single key/value pair where the key represents the measurement outcome.

Examples

We create a local QuantumNetworkServer, connect a client and run a QuantumCircuit.

>>> from qrisp.quantum_network import QuantumNetworkServer, QuantumNetworkClient
>>> local_server = QuantumNetworkServer("127.0.0.1", background = True)
>>> local_server.start()
>>> client = QuantumNetworkClient(name = "alice", socket_ip = "127.0.0.1")
>>> from qrisp import QuantumCircuit
>>> qc = QuantumCircuit(2)
>>> qc.h(0)
>>> qc.cx(0,1)
>>> qc.measure([0,1])
>>> client.run(qc)
{'11': 1}

We perform another shot

>>> client.run(qc)
{'01': 1}

After applying the first run command, the quantum state is

\[\ket{\psi} = \ket{1}\ket{1}\]

Applying the Hadamard yields

\[\text{H}_0 \ket{\psi} = \frac{1}{\sqrt{2}}(\ket{0} - \ket{1})\ket{1}\]

The CX yields

\[\text{CX}_{01} \text{H}_0 \ket{\psi} = \frac{1}{\sqrt{2}}(\ket{0}\ket{1} - \ket{1}\ket{0})\]

Finally, the measurement collapsed the state into the first summand.