next up previous contents
Next: The Graphical User Interface Up: The Bloch Sphere Previous: Bison/Flex - Adding a   Contents

Integrating the code into the language

In order to integrate the Bloch Sphere code into the QCL, a new class called sBloch was created. This class implements a pre-existing QCL class called sStmt. The scanner created by flex calls the constructor of this class once the "bloch" command has been entered at the command line. The QCL keeps the execution functions of all the classes in a file called "exec.cc". Whenever a command is called, this class contains the functions that act upon the inputted information. A new function called "sBloch::exec" was placed into this class, which takes a reference to the Quantum Heap as its argument. The Quantum Heap contains all the quantum registers allocated in the QCL. The exec function of the sBloch class checks that the quantum register is not empty, and then calls the appropriate function in the "bloch.cc" file.

The libplot library detailed above is used to draw the bloch sphere and qubit on the screen. To extract the amplitude of the qubit basevectors, a const_iterator object provided by the QCL is used. This serves as an iterator to an object of type map$<$bitvec,complx$>$, called state_map. This object is a map of the basevector and corresponding amplitude of each basevector in the quantum state. Below is an example, of how this object is used to extract an amplitude of a basevector;


\begin{lstlisting}[frame=trbl,caption=Extract from bloch.cc]{}
state_iter i;
sta...
..._m->begin();
tComplex z = (*i).second;
double alpha = z.real();
\end{lstlisting}


When the amplitudes are extracted, they are passed through to the drawing functions in "bloch.cc", and the qubit is drawn on the bloch sphere.


next up previous contents
Next: The Graphical User Interface Up: The Bloch Sphere Previous: Bison/Flex - Adding a   Contents
Colm O hEigeartaigh 2003-05-30