#!/usr/bin/env python # coding: utf-8 # # Creation of an EPR pair using two qubits # # # # Let us start with a simple circuit: the creation of an EPR pair using two qubits. # # # First, we need to import relevant objects from the python AQASM module: # In[ ]: from qat.lang.AQASM import Program, H, CNOT # ## Creation of the quantum program # # Then, we can declare a new object ``Program``. Let us give it an explicit name: # In[ ]: epr_prog = Program() # To create our EPR pair, we need to manipulate two qbits. # Qbits are manipulated through qbit registers only (to keep things structured). # Registers are allocated as follows: # In[ ]: qbits = epr_prog.qalloc(2) # Now, we can access our qbits using the register "qbits". # # Registers behave like python list/arrays. # # Here our qbits will be refered to using qbits[0] and qbits[1]. # # To create our EPR pair, we simply implement the appropriate 2-qbit rotation using a Hadamard gate (H) on the first qbit, followed by a controlled NOT gate (CNOT) on both qbits: # In[ ]: epr_prog.apply(H, qbits[0]) epr_prog.apply(CNOT, qbits) # Notice that since the CNOT is applied on both qbits (it is a 2-qbit gate), we can pass the whole register as argument to the ``.apply`` method. # The corresponding circuit object can be extracted directly from the Program object as follows: # In[ ]: circuit = epr_prog.to_circ() get_ipython().run_line_magic('qatdisplay', 'circuit') # ## Simulation of the execution of the circuit # Now that we have a proper circuit, we can try and simulate it: # In[ ]: #Let us import some qpu connected to a classical linear algebra simulator from qat.qpus import PyLinalg qpu = PyLinalg() job = circuit.to_job() result = qpu.submit(job) for sample in result: print("State", sample.state, "with amplitude", sample.amplitude) # ## Export to Atos Quantum Assembly Language (AQASM) format # We can also export our circuit in the AQASM format: # In[ ]: epr_prog.export("helloworld.aqasm") # The generated file *helloworld.aqasm* should look like this: # In[ ]: get_ipython().system('cat helloworld.aqasm') # and can be compiled to circ format as follows: # In[ ]: get_ipython().system('aqasm2circ helloworld.aqasm') # In[ ]: