[−][src]Crate cqc
CQC Interface Library
The Classical-Quantum Combiner (CQC) interface is used to program quantum networking nodes to create, transmit, and manipulate qubits.
The CQC interface will be used to interact with the Dutch demonstration network, currently under development at QuTech in the Netherlands. At present, the CQC interface is supported only by the quantum network simulator Simulaqron.
This crate provides an encoder and decoder for CQC protocol packets. It does not provide any I/O capabilities in order to maximise reusability by not putting any runtime constraints on the user.
Principle of Operation
This library provides two functions:
-
Build valid CQC packets.
-
Encode/decode to/from binary format. It is left to the user to decide how best to fit I/O in their framework.
Building Packets
This crate offers two ways of building packets
-
Manually - one can manually build packets using the header definitions and documentation provided in the
hdr
module. -
Using the
builder
module - the builder module provides a simple API for generating CQC packets. It should be used in conjunction with the CQC interface documentation in thehdr
module.
Encoding/decoding packets
All headers in the hdr
module implement serde
's Serialize
and
Deserialize
traits which mean they can be directly used as input to
bincode
. The Encoder
and Decoder
impls provide an example.
The builder
module returns a Request
struct which implements
Serialize
which can be used with bincode
.
The library provides a Response
struct which implements Deserialize
and
can be used to deserialize any response from the SimulaQron server.
Example
The following example will create a qubit on one node and send it to
another node. Before running the example below start up the SimulaQron
nodes with $NETSIM/run/startAll.sh --nrnodes 2
.
extern crate bincode; extern crate cqc; use cqc::builder; use cqc::hdr; use std::net; // Initialise local node `localhost:8803`. let hostname = String::from("localhost"); let local_port: u16 = 8803; // Set up remote node `127.0.0.1:8804`. let remote_host: u32 = u32::from(net::Ipv4Addr::new(127, 0, 0, 1)); let remote_port: u16 = 8804; // Initialise application state with ID 10. let app_id: u16 = 10; let builder = builder::Builder::new(app_id); let mut coder = bincode::config(); coder.big_endian(); // Create, and send a qubit from `localhost:8803` to `localhost:8804`. { // Open connection to local node. let stream = net::TcpStream::connect((hostname.as_str(), local_port)) .expect("Connect failed"); // Create the qubit. let request = builder.cmd_new(0, hdr::CmdOpt::empty()); coder.serialize_into(&stream, &request).expect( "Sending failed", ); // Wait for confirmation of creation. let response: cqc::Response = coder.deserialize_from(&stream).expect("Receive failed"); // Read the created qubit ID. let note = response.notify.get_qubit_hdr(); let qubit_id = note.qubit_id; // Send the qubit to the remote node. let request = builder.cmd_send( qubit_id, *hdr::CmdOpt::empty().set_notify(), builder::RemoteId { remote_app_id: app_id, remote_node: remote_host, remote_port: remote_port, }, ); coder.serialize_into(&stream, &request).expect( "Sending failed", ); // Wait for confirmation. let response: cqc::Response = coder.deserialize_from(&stream).expect("Receive failed"); assert!(response.cqc_hdr.msg_type.is_done(), "Unexpected response"); } // Receive the qubit on the remote node, `localhost:8804`. { // Open connection to local node. let stream = net::TcpStream::connect((hostname.as_str(), remote_port)) .expect("Connect failed"); // Send a request to receive a qubit. let request = builder.cmd_recv(0, hdr::CmdOpt::empty()); coder.serialize_into(&stream, &request).expect( "Sending failed", ); // Receive a response. let response: cqc::Response = coder.deserialize_from(&stream).expect("Receive failed"); assert!(response.cqc_hdr.msg_type.is_recv(), "Unexpected response"); let note = response.notify.get_qubit_hdr(); let qubit_id = note.qubit_id; println!("Received qubit ID: {}", qubit_id); }
Modules
builder | CQC Packet builder |
hdr | CQC Interface |
Structs
Decoder | Packet decoder |
Encoder | Packet encoder |
EprInfo | EPR Info |
ReqCmd | Command Request |
Request | Request |
Response | Response |
Enums
RspInfo | Response Info |
XtraHdr | Extra Header |