def main(): # In this example, we are Alice. myName = "Alice" # This file defines the network of virtual quantum nodes simulaqron_path = get_simulaqron_path.main() virtualFile = os.path.join(simulaqron_path, "config/virtualNodes.cfg") # This file defines the nodes acting as servers in the classical communication network classicalFile = "classicalNet.cfg" # Read configuration files for the virtual quantum, as well as the classical network virtualNet = networkConfig(virtualFile) classicalNet = networkConfig(classicalFile) # Check if we should run a local classical server. If so, initialize the code # to handle remote connections on the classical communication network if myName in classicalNet.hostDict: lNode = localNode(classicalNet.hostDict[myName], classicalNet) else: lNode = None # Set up the local classical server if applicable, and connect to the virtual # node and other classical servers. Once all connections are set up, this will # execute the function runClientNode setup_local(myName, virtualNet, classicalNet, lNode, runClientNode)
def main(myName): """Start the indicated backend CQC Server""" signal.signal(signal.SIGTERM, sigterm_handler) signal.signal(signal.SIGINT, sigterm_handler) logging.basicConfig( format="%(asctime)s:%(levelname)s:%(message)s", level=Settings.CONF_LOGGING_LEVEL_BACKEND, ) # This file defines the network of virtual quantum nodes virtualFile = Settings.CONF_VNODE_FILE # This file defines the network of CQC servers interfacing to virtual quantum nodes cqcFile = Settings.CONF_CQC_FILE # Read configuration files for the virtual quantum, as well as the classical network virtualNet = networkConfig(virtualFile) cqcNet = networkConfig(cqcFile) # Check if we are in the host-dictionary if myName in cqcNet.hostDict: myHost = cqcNet.hostDict[myName] cqc_factory = CQCFactory(myHost, myName, cqcNet, SimulaqronCQCHandler) else: logging.error( "LOCAL %s: Cannot start classical communication servers.", myName) return # Connect to the local virtual node simulating the "local" qubits connect_to_virtNode(myName, cqc_factory, virtualNet) # Run reactor reactor.run()
def _check_port_available(hostname, port): """ Checks if the given port is not already set in the config files or used by some other process. :param hostname: str Hostname, e.g. localhost or 192.168.0.1 :param port: int The port number :return: bool """ for config_file in config_files: network_config = networkConfig(config_file) for name, host in network_config.hostDict.items(): if port == host.port: return False return _check_socket_is_free(hostname, port)
def main(): # Read config file config = networkConfig("../../../config/virtualNodes.cfg") # We are Alice myName = "Alice" # Connect to the local virtual Node node = config.hostDict[myName] factory = pb.PBClientFactory() reactor.connectTCP(node.hostname, node.port, factory) def1 = factory.getRootObject() def1.addCallback(got_root) def1.addErrback(err_obj1) reactor.run()
def init(name, cqcFile=None): """ Initialize a connection to the cqc server with the name given as input. A path to a configure file for the cqc network can be given, if it's not given the config file 'config/cqcNodes.cfg' will be used. Returns a socket object. """ # This file defines the network of CQC servers interfacing to virtual quantum nodes if cqcFile is None: simulaqron_path = get_simulaqron_path.main() cqcFile = os.path.join(simulaqron_path, "config/cqcNodes.cfg") # Read configuration files for the cqc network cqcNet = networkConfig(cqcFile) # Host data if name in cqcNet.hostDict: myHost = cqcNet.hostDict[name] else: logging.error("The name '%s' is not in the cqc network.", name) raise LookupError( "The name '%s' is not in the cqc network.".format(name)) addr = myHost.addr # Connect to cqc server and run protocol cqc = None try: cqc = socket.socket(addr[0], addr[1], addr[2]) except socket.error: logging.error("Could not connect to cqc server: %s", name) try: cqc.connect(addr[4]) except socket.error: cqc.close() logging.error("Could not connect to cqc server: %s", name) return cqc
# 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # 3. All advertising materials mentioning features or use of this software # must display the following acknowledgement: # This product includes software developed by Stephanie Wehner, QuTech. # 4. Neither the name of the QuTech organization nor the # names of its contributors may be used to endorse or promote products # derived from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ''AS IS'' AND ANY # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. from simulaqron.general.hostConfig import networkConfig newNet = networkConfig("network.cfg") newNet.print_details("Alice") newNet.print_details("Bob") newNet.print_details("Charlie")