qgame++.h

00001 /***************************************************************************
00002  *   QGame++                                                               *
00003  *   =======                                                               *
00004  *   A Quantum Gate And Measurement Emulator.                              *
00005  *                                                                         *
00006  *   Copyright (C) 2003/04 by Manuel Nickschas                             *
00007  *   <qgame-devel@nickschas.de>                                            *
00008  *                                                                         *
00009  *   This program is free software; you can redistribute it and/or modify  *
00010  *   it under the terms of the GNU General Public License as published by  *
00011  *   the Free Software Foundation; either version 2 of the License, or     *
00012  *   (at your option) any later version.                                   *
00013  *                                                                         *
00014  *   This program is distributed in the hope that it will be useful,       *
00015  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00016  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00017  *   GNU General Public License for more details.                          *
00018  *                                                                         *
00019  *   You should have received a copy of the GNU General Public License     *
00020  *   along with this program; if not, write to the                         *
00021  *   Free Software Foundation, Inc.,                                       *
00022  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00023  ***************************************************************************/
00024  
00025 #ifndef _QGAME___H_
00026 #define _QGAME___H_
00027   
00028 #include "qgtypes.h"
00029 #include "qgerror.h"
00030 #include "qggates.h"
00031 #include "qgprog.h"
00032 
00033 #include <string>
00034 #include <vector>
00035 
00036 namespace qgame {
00037 
00045   struct Result {
00046     int misses;           
00047     double maxError;      
00048     double avgError;      
00049     double maxExpOracles; 
00050     double avgExpOracles; 
00051   };
00052   std::ostream & operator<<(std::ostream &, const Result &);
00053   
00058   struct Measurement {
00059     int qubit;    
00060     int result;   
00061     double prob;  
00062   };
00063 
00082   class QSys {
00083     QProgram *prg;
00084     int instrPnt;
00085     double prob;
00086   
00087     int numQubits;
00088     Qureg reg;
00089     std::string oracleTT;
00090     int oracleCount;
00091     std::vector<Measurement> measureHistory;
00092     std::vector<bool> execInstr;  // for branch handling
00093 
00094     std::vector<QSys*> exec() throw(Error); // internal exec without init
00095     void markBranch(bool branch); // set execInstr and instrPnt for appropriate branch
00096     void appendMeasurement(QubitList q, int outcome, double prob); // append result of measurement to hist
00097     
00098     friend std::ostream& operator<<(std::ostream &, const QSys &);
00099     
00100    public:
00101     QSys();
00102     ~QSys();
00103     void init(int numQubits, QProgram *prg, const std::string &oracleTT);
00107     QSys *clone(double priorProb); 
00110     static std::vector<QSys*> execute(int numQubits, QProgram *prg, const std::string &oracleTT) throw(Error);
00115     static Result testProgram(
00116                         int numQubits,                       
00117                         QProgram *prg,                       
00118                         const std::vector<TestCase> &cases,  
00119                         const QubitList &finalMeasure,       
00120                         double threshold                     
00121                   ) throw(Error); 
00124     Qureg  getReg();                  
00125     void   setReg(const Qureg &);     
00126     double getProb();                 
00127     void   setProb(double prob);      
00128     int    getOracleCount();          
00129     std::vector<Measurement> getMeasurementHistory();   
00131     void apply(QGate *, const QubitList &) throw(Error); 
00132     void apply(const QInstr &) throw(Error); 
00135   };
00136   
00137   std::ostream& operator<<(std::ostream &, const QSys &);
00139 };
00140 
00141 #endif

Generated on Sat Apr 3 18:42:27 2004 for QGame++ by doxygen 1.3.5