OSDN Git Service

Initial Commit
authorH. Watanabe <kaityo@users.sourceforge.jp>
Fri, 17 Apr 2015 01:06:51 +0000 (10:06 +0900)
committerH. Watanabe <kaityo@users.sourceforge.jp>
Fri, 17 Apr 2015 01:06:51 +0000 (10:06 +0900)
260 files changed:
bmp/CCnot.bmp [new file with mode: 0644]
bmp/CRot.bmp [new file with mode: 0644]
bmp/Cnot.bmp [new file with mode: 0644]
bmp/Cswap.bmp [new file with mode: 0644]
bmp/Rot.bmp [new file with mode: 0644]
bmp/TextBox.bmp [new file with mode: 0644]
bmp/Walsh.bmp [new file with mode: 0644]
bmp/X.bmp [new file with mode: 0644]
bmp/Y.bmp [new file with mode: 0644]
bmp/Z.bmp [new file with mode: 0644]
bmp/arrow.bmp [new file with mode: 0644]
bmp/erase.bmp [new file with mode: 0644]
bmp/measure.bmp [new file with mode: 0644]
bmp/measure2.bmp [new file with mode: 0644]
bmp/not.bmp [new file with mode: 0644]
bmp/qcad.bmp [new file with mode: 0644]
bmp/swap.bmp [new file with mode: 0644]
calcunits/QBits.cpp [new file with mode: 0644]
calcunits/QBits.h [new file with mode: 0644]
calcunits/QC_all.h [new file with mode: 0644]
calcunits/QC_ccnot.cpp [new file with mode: 0644]
calcunits/QC_ccnot.h [new file with mode: 0644]
calcunits/QC_cnot.cpp [new file with mode: 0644]
calcunits/QC_cnot.h [new file with mode: 0644]
calcunits/QC_crot.cpp [new file with mode: 0644]
calcunits/QC_crot.h [new file with mode: 0644]
calcunits/QC_hadamard.cpp [new file with mode: 0644]
calcunits/QC_hadamard.h [new file with mode: 0644]
calcunits/QC_measure.cpp [new file with mode: 0644]
calcunits/QC_measure.h [new file with mode: 0644]
calcunits/QC_not.cpp [new file with mode: 0644]
calcunits/QC_not.h [new file with mode: 0644]
calcunits/QC_pauliX.cpp [new file with mode: 0644]
calcunits/QC_pauliX.h [new file with mode: 0644]
calcunits/QC_pauliY.cpp [new file with mode: 0644]
calcunits/QC_pauliY.h [new file with mode: 0644]
calcunits/QC_pauliZ.cpp [new file with mode: 0644]
calcunits/QC_pauliZ.h [new file with mode: 0644]
calcunits/QC_rot.cpp [new file with mode: 0644]
calcunits/QC_rot.h [new file with mode: 0644]
calcunits/QC_swap.cpp [new file with mode: 0644]
calcunits/QC_swap.h [new file with mode: 0644]
calcunits/QCalcManager.cpp [new file with mode: 0644]
calcunits/QCalcManager.h [new file with mode: 0644]
calcunits/QCalcUnit.cpp [new file with mode: 0644]
calcunits/QCalcUnit.h [new file with mode: 0644]
calcunits/makefile [new file with mode: 0644]
circuits/QBitbox.cpp [new file with mode: 0644]
circuits/QBitbox.h [new file with mode: 0644]
circuits/QCCnot.cpp [new file with mode: 0644]
circuits/QCCnot.h [new file with mode: 0644]
circuits/QCRot.cpp [new file with mode: 0644]
circuits/QCRot.h [new file with mode: 0644]
circuits/QCircuit.cpp [new file with mode: 0644]
circuits/QCircuit.h [new file with mode: 0644]
circuits/QCircuitAll.h [new file with mode: 0644]
circuits/QCnot.cpp [new file with mode: 0644]
circuits/QCnot.h [new file with mode: 0644]
circuits/QMeasure.cpp [new file with mode: 0644]
circuits/QMeasure.h [new file with mode: 0644]
circuits/QNot.cpp [new file with mode: 0644]
circuits/QNot.h [new file with mode: 0644]
circuits/QPauliX.cpp [new file with mode: 0644]
circuits/QPauliX.h [new file with mode: 0644]
circuits/QPauliY.cpp [new file with mode: 0644]
circuits/QPauliY.h [new file with mode: 0644]
circuits/QPauliZ.cpp [new file with mode: 0644]
circuits/QPauliZ.h [new file with mode: 0644]
circuits/QRot.cpp [new file with mode: 0644]
circuits/QRot.h [new file with mode: 0644]
circuits/QSwap.cpp [new file with mode: 0644]
circuits/QSwap.h [new file with mode: 0644]
circuits/QWalsh.cpp [new file with mode: 0644]
circuits/QWalsh.h [new file with mode: 0644]
circuits/makefile [new file with mode: 0644]
compiler/000.txt [new file with mode: 0644]
compiler/QCompiler.cpp [new file with mode: 0644]
compiler/QCompiler.h [new file with mode: 0644]
compiler/QCompilerCntl.cpp [new file with mode: 0644]
compiler/QCompilerCntl.h [new file with mode: 0644]
compiler/QCompilerCode.cpp [new file with mode: 0644]
compiler/QCompilerCode.h [new file with mode: 0644]
compiler/QParseInfo.cpp [new file with mode: 0644]
compiler/QParseInfo.h [new file with mode: 0644]
compiler/compiler_main.cpp [new file with mode: 0644]
compiler/makefile [new file with mode: 0644]
compiler/makefile_bcc [new file with mode: 0644]
compiler/man/man1/qcc.1 [new file with mode: 0644]
compiler/man/man1/qcpp.1 [new file with mode: 0644]
compiler/man/man1/qcrun.1 [new file with mode: 0644]
compiler/qcc [new file with mode: 0644]
compiler/qcpp.cpp [new file with mode: 0644]
compiler/qcrun.cpp [new file with mode: 0644]
compiler/sample.mcd [new file with mode: 0644]
compiler/sample.qcd [new file with mode: 0644]
htdocs/img/00new.png [new file with mode: 0644]
htdocs/img/01open.png [new file with mode: 0644]
htdocs/img/02save.png [new file with mode: 0644]
htdocs/img/03undo.png [new file with mode: 0644]
htdocs/img/04remove.png [new file with mode: 0644]
htdocs/img/05help.png [new file with mode: 0644]
htdocs/img/06run.png [new file with mode: 0644]
htdocs/img/07saveasbmp.png [new file with mode: 0644]
htdocs/img/08saveasps.png [new file with mode: 0644]
htdocs/img/arrow.png [new file with mode: 0644]
htdocs/img/ccnot.png [new file with mode: 0644]
htdocs/img/cnot.png [new file with mode: 0644]
htdocs/img/copy.png [new file with mode: 0644]
htdocs/img/crot.png [new file with mode: 0644]
htdocs/img/cswap.png [new file with mode: 0644]
htdocs/img/cut.png [new file with mode: 0644]
htdocs/img/download.png [new file with mode: 0644]
htdocs/img/edit.png [new file with mode: 0644]
htdocs/img/epsexport.png [new file with mode: 0644]
htdocs/img/erase.png [new file with mode: 0644]
htdocs/img/measure.png [new file with mode: 0644]
htdocs/img/measure2.png [new file with mode: 0644]
htdocs/img/measurement1.png [new file with mode: 0755]
htdocs/img/measurement2.png [new file with mode: 0755]
htdocs/img/measurement3.png [new file with mode: 0755]
htdocs/img/measurement4.png [new file with mode: 0755]
htdocs/img/mesure.png [new file with mode: 0644]
htdocs/img/mesure2.png [new file with mode: 0644]
htdocs/img/not.png [new file with mode: 0644]
htdocs/img/paste.png [new file with mode: 0644]
htdocs/img/qcad.png [new file with mode: 0644]
htdocs/img/qcad1.png [new file with mode: 0644]
htdocs/img/qcad2.png [new file with mode: 0644]
htdocs/img/qcad3.png [new file with mode: 0644]
htdocs/img/qcad4.png [new file with mode: 0644]
htdocs/img/qcadico48.png [new file with mode: 0644]
htdocs/img/qcadps.png [new file with mode: 0644]
htdocs/img/qcadr1.png [new file with mode: 0644]
htdocs/img/qcadr1_s.png [new file with mode: 0644]
htdocs/img/qcadr2.png [new file with mode: 0644]
htdocs/img/qcadr2_s.png [new file with mode: 0644]
htdocs/img/qcadr3.png [new file with mode: 0644]
htdocs/img/qcadr3_s.png [new file with mode: 0644]
htdocs/img/qcadr4.png [new file with mode: 0644]
htdocs/img/qcadr4_s.png [new file with mode: 0644]
htdocs/img/qcads.png [new file with mode: 0644]
htdocs/img/qcads_s.png [new file with mode: 0644]
htdocs/img/qgates.png [new file with mode: 0644]
htdocs/img/rot.png [new file with mode: 0644]
htdocs/img/swap.png [new file with mode: 0644]
htdocs/img/walsh.png [new file with mode: 0644]
htdocs/img/x.png [new file with mode: 0644]
htdocs/img/y.png [new file with mode: 0644]
htdocs/img/z.png [new file with mode: 0644]
htdocs/index.html [new file with mode: 0644]
htdocs/index_j.html [new file with mode: 0644]
htdocs/makefile [new file with mode: 0644]
htdocs/makehhc.rb [new file with mode: 0644]
htdocs/qcadhelp.hhp [new file with mode: 0644]
htdocs/qcadhelp.html [new file with mode: 0644]
htdocs/qcadhelp.rd [new file with mode: 0644]
htdocs/style.css [new file with mode: 0644]
makefile [new file with mode: 0644]
qcadwin/000.txt [new file with mode: 0644]
qcadwin/CPanel.cpp [new file with mode: 0644]
qcadwin/CPanel.dfm [new file with mode: 0644]
qcadwin/CPanel.h [new file with mode: 0644]
qcadwin/Graph.cpp [new file with mode: 0644]
qcadwin/Graph.dfm [new file with mode: 0644]
qcadwin/Graph.h [new file with mode: 0644]
qcadwin/HHelp.cpp [new file with mode: 0644]
qcadwin/HHelp.h [new file with mode: 0644]
qcadwin/Input.cpp [new file with mode: 0644]
qcadwin/Input.dfm [new file with mode: 0644]
qcadwin/Input.h [new file with mode: 0644]
qcadwin/New.cpp [new file with mode: 0644]
qcadwin/New.dfm [new file with mode: 0644]
qcadwin/New.h [new file with mode: 0644]
qcadwin/Param.cpp [new file with mode: 0644]
qcadwin/Param.dfm [new file with mode: 0644]
qcadwin/Param.h [new file with mode: 0644]
qcadwin/Preview.cpp [new file with mode: 0644]
qcadwin/Preview.dfm [new file with mode: 0644]
qcadwin/Preview.h [new file with mode: 0644]
qcadwin/QAbstractDraw.cpp [new file with mode: 0644]
qcadwin/QAbstractDraw.h [new file with mode: 0644]
qcadwin/QDraw.cpp [new file with mode: 0644]
qcadwin/QDraw.h [new file with mode: 0644]
qcadwin/QDrawGraph.cpp [new file with mode: 0644]
qcadwin/QDrawGraph.h [new file with mode: 0644]
qcadwin/QDrawHSVGraph.cpp [new file with mode: 0644]
qcadwin/QDrawHSVGraph.h [new file with mode: 0644]
qcadwin/QManager.cpp [new file with mode: 0644]
qcadwin/QManager.h [new file with mode: 0644]
qcadwin/QPSDraw.cpp [new file with mode: 0644]
qcadwin/QPSDraw.h [new file with mode: 0644]
qcadwin/QSelector.cpp [new file with mode: 0644]
qcadwin/QSelector.h [new file with mode: 0644]
qcadwin/QUndoManager.cpp [new file with mode: 0644]
qcadwin/QUndoManager.h [new file with mode: 0644]
qcadwin/StrUtils.cpp [new file with mode: 0644]
qcadwin/StrUtils.h [new file with mode: 0644]
qcadwin/Version.cpp [new file with mode: 0644]
qcadwin/Version.dfm [new file with mode: 0644]
qcadwin/Version.h [new file with mode: 0644]
qcadwin/bitmap.rc [new file with mode: 0644]
qcadwin/bitmap.res [new file with mode: 0644]
qcadwin/icon/00new.bmp [new file with mode: 0644]
qcadwin/icon/01open.bmp [new file with mode: 0644]
qcadwin/icon/02save.bmp [new file with mode: 0644]
qcadwin/icon/03undo.bmp [new file with mode: 0644]
qcadwin/icon/04remove.bmp [new file with mode: 0644]
qcadwin/icon/05help.bmp [new file with mode: 0644]
qcadwin/icon/06run.bmp [new file with mode: 0644]
qcadwin/icon/07saveasbmp.bmp [new file with mode: 0644]
qcadwin/icon/08saveasps.bmp [new file with mode: 0644]
qcadwin/icon/copy.bmp [new file with mode: 0644]
qcadwin/icon/cut.bmp [new file with mode: 0644]
qcadwin/icon/edit.bmp [new file with mode: 0644]
qcadwin/icon/oldicon.ico [new file with mode: 0644]
qcadwin/icon/oldicon16.ico [new file with mode: 0644]
qcadwin/icon/paste.bmp [new file with mode: 0644]
qcadwin/icon/qcadico.ai [new file with mode: 0644]
qcadwin/icon/qcadico.ico [new file with mode: 0644]
qcadwin/icon/qcadico.png [new file with mode: 0644]
qcadwin/icon/qcadico16.ai [new file with mode: 0644]
qcadwin/icon/qcadico16.png [new file with mode: 0644]
qcadwin/icon/qcadico32.png [new file with mode: 0644]
qcadwin/icon/qcadico48.png [new file with mode: 0644]
qcadwin/main.cpp [new file with mode: 0644]
qcadwin/main.dfm [new file with mode: 0644]
qcadwin/main.h [new file with mode: 0644]
qcadwin/makefile [new file with mode: 0644]
qcadwin/qcad.bpr [new file with mode: 0644]
qcadwin/qcad.cpp [new file with mode: 0644]
qcadwin/qcad.mak [new file with mode: 0644]
qcadwin/qcad.res [new file with mode: 0644]
qcadwin/sample1.mcd [new file with mode: 0644]
qcadwin/sample1.qcd [new file with mode: 0644]
qcadwin/swap_endian.h [new file with mode: 0644]
qcadwin/undo/QUndoAdd.cpp [new file with mode: 0644]
qcadwin/undo/QUndoAdd.h [new file with mode: 0644]
qcadwin/undo/QUndoInsertColumn.cpp [new file with mode: 0644]
qcadwin/undo/QUndoInsertColumn.h [new file with mode: 0644]
qcadwin/undo/QUndoModify.cpp [new file with mode: 0644]
qcadwin/undo/QUndoModify.h [new file with mode: 0644]
qcadwin/undo/QUndoQuitSelect.cpp [new file with mode: 0644]
qcadwin/undo/QUndoQuitSelect.h [new file with mode: 0644]
qcadwin/undo/QUndoRemove.cpp [new file with mode: 0644]
qcadwin/undo/QUndoRemove.h [new file with mode: 0644]
qcadwin/undo/QUndoUnit.cpp [new file with mode: 0644]
qcadwin/undo/QUndoUnit.h [new file with mode: 0644]
qclib/makefile [new file with mode: 0644]
qclib/qcbitcalc.h [new file with mode: 0644]
qclib/qccalccore.h [new file with mode: 0644]
qclib/qclib.cpp [new file with mode: 0644]
qclib/qclib.h [new file with mode: 0644]
qclib/qcunitcalc.h [new file with mode: 0644]
qclibmpi/main.cc [new file with mode: 0644]
qclibmpi/makefile [new file with mode: 0644]
release/LICENSE.TXT [new file with mode: 0644]
release/README.TXT [new file with mode: 0644]
release/makefile [new file with mode: 0644]
samples/qft3iqft.qcd [new file with mode: 0644]
samples/sample1.qcd [new file with mode: 0644]

diff --git a/bmp/CCnot.bmp b/bmp/CCnot.bmp
new file mode 100644 (file)
index 0000000..aefefed
Binary files /dev/null and b/bmp/CCnot.bmp differ
diff --git a/bmp/CRot.bmp b/bmp/CRot.bmp
new file mode 100644 (file)
index 0000000..8aa9fa7
Binary files /dev/null and b/bmp/CRot.bmp differ
diff --git a/bmp/Cnot.bmp b/bmp/Cnot.bmp
new file mode 100644 (file)
index 0000000..b34c416
Binary files /dev/null and b/bmp/Cnot.bmp differ
diff --git a/bmp/Cswap.bmp b/bmp/Cswap.bmp
new file mode 100644 (file)
index 0000000..f16000a
Binary files /dev/null and b/bmp/Cswap.bmp differ
diff --git a/bmp/Rot.bmp b/bmp/Rot.bmp
new file mode 100644 (file)
index 0000000..57f0d9c
Binary files /dev/null and b/bmp/Rot.bmp differ
diff --git a/bmp/TextBox.bmp b/bmp/TextBox.bmp
new file mode 100644 (file)
index 0000000..a528750
Binary files /dev/null and b/bmp/TextBox.bmp differ
diff --git a/bmp/Walsh.bmp b/bmp/Walsh.bmp
new file mode 100644 (file)
index 0000000..3944754
Binary files /dev/null and b/bmp/Walsh.bmp differ
diff --git a/bmp/X.bmp b/bmp/X.bmp
new file mode 100644 (file)
index 0000000..4344194
Binary files /dev/null and b/bmp/X.bmp differ
diff --git a/bmp/Y.bmp b/bmp/Y.bmp
new file mode 100644 (file)
index 0000000..748d22c
Binary files /dev/null and b/bmp/Y.bmp differ
diff --git a/bmp/Z.bmp b/bmp/Z.bmp
new file mode 100644 (file)
index 0000000..a0dbb0c
Binary files /dev/null and b/bmp/Z.bmp differ
diff --git a/bmp/arrow.bmp b/bmp/arrow.bmp
new file mode 100644 (file)
index 0000000..0e864e3
Binary files /dev/null and b/bmp/arrow.bmp differ
diff --git a/bmp/erase.bmp b/bmp/erase.bmp
new file mode 100644 (file)
index 0000000..65b49ab
Binary files /dev/null and b/bmp/erase.bmp differ
diff --git a/bmp/measure.bmp b/bmp/measure.bmp
new file mode 100644 (file)
index 0000000..5c20ec9
Binary files /dev/null and b/bmp/measure.bmp differ
diff --git a/bmp/measure2.bmp b/bmp/measure2.bmp
new file mode 100644 (file)
index 0000000..ee107c8
Binary files /dev/null and b/bmp/measure2.bmp differ
diff --git a/bmp/not.bmp b/bmp/not.bmp
new file mode 100644 (file)
index 0000000..747aeb6
Binary files /dev/null and b/bmp/not.bmp differ
diff --git a/bmp/qcad.bmp b/bmp/qcad.bmp
new file mode 100644 (file)
index 0000000..f79efab
Binary files /dev/null and b/bmp/qcad.bmp differ
diff --git a/bmp/swap.bmp b/bmp/swap.bmp
new file mode 100644 (file)
index 0000000..e35de5d
Binary files /dev/null and b/bmp/swap.bmp differ
diff --git a/calcunits/QBits.cpp b/calcunits/QBits.cpp
new file mode 100644 (file)
index 0000000..a0ed6a4
--- /dev/null
@@ -0,0 +1,446 @@
+//---------------------------------------------------------------------------\r
+//  Represent bits states\r
+//---------------------------------------------------------------------------\r
+#ifdef __BORLANDC__\r
+#include <vcl.h>\r
+#pragma hdrstop\r
+#endif //__BORLANDC__\r
+\r
+#include <iostream>\r
+#include <fstream>\r
+#include <string>\r
+#include <new>\r
+#include <cstdlib>\r
+#include <math.h>\r
+#include "QBits.h"\r
+\r
+using namespace std;\r
+\r
+//---------------------------------------------------------------------------\r
+#ifdef __BORLANDC__\r
+#pragma package(smart_init)\r
+#endif //__BORLANDC__\r
+//---------------------------------------------------------------------------\r
+/**\r
+ *  operator<<\r
+ */\r
+std::ostream &\r
+operator<<(std::ostream &os, const QBits &qb) {\r
+\r
+    std::string s1;\r
+    for (int i = 0; i < qb.mNumberOfStates; i++) {\r
+        s1 = "";\r
+        for (int j = 0; j < qb.mNumberOfQbits; j++) {\r
+            if ((i >> j) & 1) {\r
+                s1 = "1" + s1;\r
+            } else {\r
+                s1 = "0" + s1;\r
+            }\r
+        }\r
+        s1 = "|" + s1 + "> = ";\r
+        os << s1 << qb.mBitsR[i]\r
+        << " + " << qb.mBitsI[i]\r
+        << "i\n";\r
+    }\r
+    return os;\r
+}\r
+//---------------------------------------------------------------------------\r
+/**\r
+ *  operator<<\r
+ */\r
+std::ostream\r
+&operator<<(std::ostream &os, const QBits *qb) {\r
+    return (os << *qb);\r
+}\r
+//---------------------------------------------------------------------------\r
+/**\r
+ *  Constructor\r
+ */\r
+QBits::QBits(char * filename) {\r
+    LoadFromFile(filename);\r
+}\r
+//---------------------------------------------------------------------------\r
+/**\r
+ *  Constructor\r
+ */\r
+QBits::QBits(void) {\r
+    mBitsR = NULL;\r
+    mBitsI = NULL;\r
+    mBitsM = NULL;\r
+    mMeasured =NULL;\r
+    bValid = false;\r
+}\r
+//---------------------------------------------------------------------------\r
+/**\r
+ *  Constructor\r
+ */\r
+QBits::QBits(const int n) {\r
+    mBitsR = NULL;\r
+    mBitsI = NULL;\r
+    mBitsM = NULL;\r
+    mMeasured =NULL;\r
+    bValid = false;\r
+\r
+    Allocate(n);\r
+}\r
+//---------------------------------------------------------------------------\r
+/**\r
+ *  Copy constructor\r
+ */\r
+QBits::QBits(const QBits &qubits)\r
+{\r
+    mNumberOfQbits  = qubits.mNumberOfQbits;\r
+    mNumberOfStates = qubits.mNumberOfStates;\r
+    try {\r
+        mBitsR = new double [mNumberOfStates];\r
+        mBitsI = new double [mNumberOfStates];\r
+        mMeasured = new bool [mNumberOfQbits];\r
+        mBitsM = new double[GetNumberOfMeasured()];\r
+    } catch (std::bad_alloc ex) {\r
+#ifdef __BORLANDC__\r
+        ShowMessage("QBits: fatal error. Out of Memory.");\r
+#endif //__BORLANDC__\r
+        std::exit(1);\r
+    }\r
+\r
+    for (int i = 0; i < mNumberOfStates; i++){\r
+        mBitsR[i] = qubits.mBitsR[i];\r
+        mBitsI[i] = qubits.mBitsI[i];\r
+    }\r
+\r
+    for (int i=0;i<mNumberOfQbits;i++){\r
+        mMeasured[i] = qubits.mMeasured[i];\r
+        mBitsM[i] = qubits.mBitsM[i];\r
+    }\r
+\r
+}\r
+//---------------------------------------------------------------------------\r
+/**\r
+ *  Destructor\r
+ */\r
+QBits::~QBits() {\r
+    if (mBitsR != NULL) delete [] mBitsR;\r
+    if (mBitsI != NULL) delete [] mBitsI;\r
+    if (mBitsM != NULL) delete [] mBitsM;\r
+    if (mMeasured !=NULL) delete [] mMeasured;\r
+}\r
+//---------------------------------------------------------------------------\r
+bool\r
+QBits::Allocate(int n) {\r
+    mNumberOfQbits  = n;\r
+    mNumberOfStates = 1 << n;\r
+\r
+    if (bValid) {\r
+        if (mBitsR != NULL) delete [] mBitsR;\r
+        if (mBitsI != NULL) delete [] mBitsI;\r
+        if (mMeasured !=NULL) delete [] mMeasured;\r
+        if (mBitsM != NULL) delete [] mBitsM;\r
+    }\r
+\r
+    bValid = false;\r
+    try {\r
+        mBitsR = new double [mNumberOfStates];\r
+        mBitsI = new double [mNumberOfStates];\r
+        mMeasured = new bool [mNumberOfQbits];\r
+        mBitsM = new double[GetNumberOfMeasured()];\r
+    } catch (std::bad_alloc ex) {\r
+#ifdef __BORLANDC__\r
+        ShowMessage("Error: Out of Memory.");\r
+#endif //__BORLANDC__\r
+        if (mBitsR != NULL) delete [] mBitsR;\r
+        if (mBitsI != NULL) delete [] mBitsI;\r
+        if (mMeasured !=NULL) delete [] mMeasured;\r
+        if (mBitsM != NULL) delete [] mBitsM;\r
+        return false;\r
+    }\r
+    bValid = true;\r
+\r
+    Init();\r
+    return true;\r
+}\r
+//---------------------------------------------------------------------------\r
+/**\r
+ * Initialize\r
+ */\r
+void\r
+QBits::Init(void) {\r
+    for (int i = 0; i < mNumberOfStates; i++){\r
+        mBitsR[i] = 0.0;\r
+        mBitsI[i] = 0.0;\r
+    }\r
+    mBitsR[0] = 1.0;\r
+    for (int i = 0; i < mNumberOfQbits; i++){\r
+        mMeasured[i] = false;\r
+    }\r
+}\r
+//---------------------------------------------------------------------------\r
+/**\r
+ *  Get real part of nth state as reference\r
+ */\r
+double &\r
+QBits::NthStateR(const int nth) const {\r
+    if (nth < 0 || mNumberOfStates <= nth) {\r
+#ifdef __BORLANDC__\r
+        ShowMessage("QBits: fatal error");\r
+#endif //__BORLANDC__\r
+        std::exit(1);\r
+    }\r
+    return mBitsR[nth];\r
+}\r
+//---------------------------------------------------------------------------\r
+/**\r
+ *  Get imaginary part of nth state as reference\r
+ */\r
+double &\r
+QBits::NthStateI(const int nth) const {\r
+    if (nth < 0 || mNumberOfStates <= nth) {\r
+#ifdef __BORLANDC__\r
+        ShowMessage("QBits: fatal error");\r
+#endif //__BORLANDC__\r
+        std::exit(1);\r
+    }\r
+    return mBitsI[nth];\r
+}\r
+//---------------------------------------------------------------------------\r
+/**\r
+ * Return Absolute Value of index state\r
+ */\r
+double\r
+QBits::GetAbsoluteValue(int index){\r
+    double re = NthStateR(index);\r
+    double im = NthStateI(index);\r
+    return re*re+im*im;\r
+}\r
+//---------------------------------------------------------------------------\r
+// Measurement\r
+//---------------------------------------------------------------------------\r
+int\r
+QBits::GetNumberOfMeasured(void){\r
+    int n = 0;\r
+    for (int i=0;i<GetNumberOfQBits();i++){\r
+        if (isMeasured(i)) {\r
+            n++;\r
+        }\r
+    }\r
+    return n;\r
+}\r
+//---------------------------------------------------------------------------\r
+double\r
+QBits::GetMeasuredValue(int index){\r
+    return mBitsM[index];\r
+}\r
+//---------------------------------------------------------------------------\r
+string\r
+QBits::GetMeasuredString(int index){\r
+\r
+    string s;\r
+    int t = 1;\r
+    for (int j=0;j<GetNumberOfQBits();j++){\r
+        if (isMeasured(j)){\r
+            if ( (index >> (t-1) )&1){\r
+                s = "1" + s;\r
+            }else{\r
+                s = "0" + s;\r
+            }\r
+            t++;\r
+        }else{\r
+            s = "?" + s;\r
+        }\r
+    }\r
+    s = "|" + s + ">";\r
+    return s;\r
+}\r
+//---------------------------------------------------------------------------\r
+/**\r
+ *  Perform Measurement\r
+ */\r
+void\r
+QBits::PerformMeasurement(void){\r
+    if (mBitsM !=NULL){\r
+        delete [] mBitsM;\r
+    }\r
+\r
+    int n = 1 << GetNumberOfMeasured();\r
+\r
+    try{\r
+        mBitsM = new double[n];\r
+    }catch (bad_alloc ex){\r
+#ifdef __BORLANDC__\r
+        ShowMessage("QBits: fatal error. Out of Memory.");\r
+#endif\r
+        return;\r
+    }\r
+\r
+    for (int i=0;i<n;i++){\r
+        mBitsM[i] = 0;\r
+    }\r
+\r
+    for (int i=0;i< GetNumberOfStates();i++){\r
+        int index = 0;\r
+        int t = 1;\r
+        for (int j=0;j<GetNumberOfQBits();j++){\r
+            if (isMeasured(j)){\r
+                index += (((i>>j)&1)<<(t-1));\r
+                t++;\r
+            }\r
+        }\r
+        mBitsM[index] += GetAbsoluteValue(i);\r
+    }\r
+}\r
+//---------------------------------------------------------------------------\r
+#ifdef __BIG_ENDIAN__\r
+#include "swap_endian.h"\r
+#endif //__BIG_ENDIAN__\r
+//---------------------------------------------------------------------------\r
+/**\r
+ * Load data From File\r
+ */\r
+void QBits::LoadFromFile(const char *filename) {\r
+    QResultInfo ri;\r
+    FILE *fp = fopen(filename,"rb");\r
+\r
+#ifdef __BIG_ENDIAN__\r
+    char    cbuf[8];\r
+    int     dummyInt;\r
+    fread(&ri.header, sizeof(char), 4, fp);\r
+    fread(&ri.filename, sizeof(char), 4, fp);\r
+    fread(&dummyInt, sizeof(int), 1, fp);\r
+    qutil::swap_endian(&dummyInt, cbuf);\r
+    ri.bitnumber = *(int*)cbuf;\r
+#else\r
+    fread(&ri,sizeof(ri),1,fp);\r
+#endif //__BIG_ENDIAN__\r
+\r
+    mNumberOfQbits  = ri.bitnumber;\r
+    mNumberOfStates = 1 << ri.bitnumber;\r
+\r
+    try {\r
+        mBitsR = new double [mNumberOfStates];\r
+        mBitsI = new double [mNumberOfStates];\r
+    } catch (std::bad_alloc ex) {\r
+\r
+#ifdef __BORLANDC__\r
+        ShowMessage("QBits: fatal error");\r
+#endif //__BORLANDC__\r
+\r
+        std::exit(1);\r
+        fclose(fp);\r
+    }\r
+\r
+#ifdef __BIG_ENDIAN__\r
+    double  dummyDouble;\r
+    for (int i = 0; i < mNumberOfStates; i++)\r
+    {\r
+        fread(&dummyDouble, sizeof(double), 1, fp);\r
+        qutil::swap_endian(&dummyDouble, cbuf);\r
+        mBitsR[i] = *(double*)cbuf;\r
+    }\r
+    for (int i = 0; i < mNumberOfStates; i++)\r
+    {\r
+        fread(&dummyDouble, sizeof(double), 1, fp);\r
+        qutil::swap_endian(&dummyDouble, cbuf);\r
+        mBitsI[i] = *(double*)cbuf;\r
+    }\r
+#else\r
+    fread(mBitsR,sizeof(double),mNumberOfStates,fp);\r
+    fread(mBitsI,sizeof(double),mNumberOfStates,fp);\r
+#endif //__BIG_ENDIAN__\r
+\r
+    fclose(fp);\r
+}\r
+//---------------------------------------------------------------------------\r
+/**\r
+ * Save data to File\r
+ */\r
+void\r
+QBits::SaveToFile(const char *filename) {\r
+    QResultInfo ri;\r
+    ri.bitnumber = GetNumberOfQBits();\r
+    strcpy(ri.filename,filename);\r
+\r
+    int datasize = 1<<GetNumberOfQBits();\r
+    double *R = GetBitsR();\r
+    double *I = GetBitsI();\r
+\r
+    FILE *fp = fopen(filename,"wb");\r
+\r
+#ifdef __BIG_ENDIAN__\r
+    char cbuf[8];\r
+    fwrite(ri.header, sizeof(char), 4, fp);\r
+    fwrite(ri.filename, sizeof(char), 256, fp);\r
+    qutil::swap_endian(&ri.bitnumber, cbuf);\r
+    fwrite(cbuf, sizeof(int), 1, fp);\r
+    for (int i = 0; i < datasize; i++) {\r
+        qutil::swap_endian(&R[i], cbuf);\r
+        fwrite(cbuf, sizeof(double), 1, fp);\r
+    }\r
+    for (int i = 0; i < datasize; i++) {\r
+        qutil::swap_endian(&I[i], cbuf);\r
+        fwrite(cbuf, sizeof(double), 1, fp);\r
+    }\r
+#else\r
+    fwrite(&ri,sizeof(ri),1,fp);\r
+    fwrite(R,sizeof(double),datasize,fp);\r
+    fwrite(I,sizeof(double),datasize,fp);\r
+#endif //__BIG_ENDIAN__\r
+    fclose(fp);\r
+}\r
+//---------------------------------------------------------------------------\r
+/**\r
+ * Save data as  Text File\r
+ */\r
+void\r
+QBits::SaveAsText(const char *filename) {\r
+\r
+    ofstream ofs;\r
+    ofs.open(filename);\r
+    ofs << "#QCAD Result file" << endl;\r
+    ofs << "#ex) Index), (Qubits conf.), (Abs. value), (Re. part), (Im. part)" << endl;\r
+    ofs << "#ex)      0, |00000>       , 1.000       , 0.4455    , 0.23      " << endl;\r
+    SaveToStream(ofs);\r
+    ofs.close();\r
+}\r
+//---------------------------------------------------------------------------\r
+void\r
+QBits::SaveMeasurementToStream(ostream &os){\r
+    int n = 1 << GetNumberOfMeasured();\r
+    for (int i=0;i<n;i++){\r
+        os << i;\r
+        os << ",  ";\r
+        os << GetMeasuredString(i);\r
+        os << ",  ";\r
+        os.setf(ios::fixed | ios::floatfield);\r
+        os.precision(8);\r
+        os.setf(ios::showpoint);\r
+        os << GetMeasuredValue(i) << endl;\r
+    }\r
+}\r
+//---------------------------------------------------------------------------\r
+/**\r
+ * Save data as  Text File\r
+ */\r
+void\r
+QBits::SaveToStream(ostream &ss){\r
+    double *R = GetBitsR();\r
+    double *I = GetBitsI();\r
+\r
+    for (int i=0;i< GetNumberOfStates();i++){\r
+        string s;\r
+        for (int j=0;j<GetNumberOfQBits();j++){\r
+            if ((i>>j)&1) {\r
+                s = "1" + s;\r
+            } else {\r
+                s = "0" + s;\r
+            }\r
+        }\r
+        s = "|" + s + ">";\r
+        double a = sqrt(R[i]*R[i]+I[i]*I[i]); //abs. value\r
+        ss << i << "," << s << ",";\r
+        ss.width(10);\r
+        ss.setf(ios::fixed, ios::floatfield);\r
+        ss.setf(ios::showpoint);\r
+        ss << a << "," << R[i] << "," << I[i] << endl;\r
+    }\r
+}\r
+//---------------------------------------------------------------------------\r
+\r
diff --git a/calcunits/QBits.h b/calcunits/QBits.h
new file mode 100644 (file)
index 0000000..8057326
--- /dev/null
@@ -0,0 +1,104 @@
+//---------------------------------------------------------------------------\r
+//  Represent bits states\r
+//---------------------------------------------------------------------------\r
+#ifndef QBITS_H\r
+#define QBITS_H\r
+//---------------------------------------------------------------------------\r
+#include <iostream>\r
+#include <sstream>\r
+#include <stdio.h>\r
+#include <string.h>\r
+\r
+using namespace std;\r
+\r
+class QResultInfo{\r
+public:\r
+    char header[4];\r
+    char filename[256];\r
+    int bitnumber;\r
+    QResultInfo(void)\r
+    {\r
+        header[0] = 'q';\r
+        header[1] = 'd';\r
+        header[2] = 'a';\r
+        header[3] = 't';\r
+        bitnumber = 0;\r
+        for (int i=0;i<256;i++)\r
+        {\r
+            filename[i] = 0;\r
+        }\r
+    }\r
+};\r
+\r
+//---------------------------------------------------------------------------\r
+\r
+class QBits\r
+{\r
+    friend std::ostream &operator<<(std::ostream &os, const QBits &qb);\r
+    friend std::ostream &operator<<(std::ostream &os, const QBits *qb);\r
+\r
+public:\r
+    QBits(void);\r
+    QBits(const int n);\r
+    QBits(char * filename);\r
+    QBits(const QBits &qubits);\r
+    ~QBits();\r
+\r
+    void Init(void);\r
+    bool Allocate(int n);\r
+    int    GetNumberOfQBits(void)  const {\r
+        return mNumberOfQbits;\r
+    }\r
+    int    GetNumberOfStates(void) const {\r
+        return mNumberOfStates;\r
+    }\r
+    void   Measure(int index){\r
+        mMeasured[index] = true;\r
+    };\r
+    bool   isMeasured(int index){\r
+        return mMeasured[index];\r
+    };\r
+    int    GetNumberOfMeasured(void);\r
+    string GetMeasuredString(int index);\r
+\r
+\r
+    double &NthStateR(const int nth) const;\r
+    double &NthStateI(const int nth) const;\r
+    double *GetBitsR(void) {\r
+        return mBitsR;\r
+    }\r
+    double *GetBitsI(void) {\r
+        return mBitsI;\r
+    }\r
+    double GetAbsoluteValue(int index);\r
+    double GetMeasuredValue(int index);\r
+\r
+    void PerformMeasurement(void);\r
+    void SaveMeasurementToStream(ostream &os);\r
+\r
+    void LoadFromFile(const char *filename);\r
+    void SaveToFile(const char *filename);\r
+    void SaveAsText(const char *filename);\r
+    void SaveToStream(ostream &ss);\r
+    bool IsValid(void){\r
+        return bValid;\r
+    };\r
+\r
+private:\r
+\r
+    bool bValid;\r
+    int mNumberOfQbits;  //n\r
+    int mNumberOfStates; //2^n\r
+    double *mBitsR;         //Re\r
+    double *mBitsI;         //Im\r
+\r
+    double *mBitsM;// Measured Values\r
+\r
+    bool *mMeasured; //Measured Flag\r
+\r
+};\r
+\r
+std::ostream &operator<<(std::ostream &os, const QBits &qb);\r
+std::ostream &operator<<(std::ostream &os, const QBits *qb);\r
+//---------------------------------------------------------------------------\r
+#endif //QBITS_H\r
diff --git a/calcunits/QC_all.h b/calcunits/QC_all.h
new file mode 100644 (file)
index 0000000..aca6e82
--- /dev/null
@@ -0,0 +1,11 @@
+#include "QBits.h"\r
+#include "QC_ccnot.h"\r
+#include "QC_cnot.h"\r
+#include "QC_crot.h"\r
+#include "QC_hadamard.h"\r
+#include "QC_not.h"\r
+#include "QC_pauliX.h"\r
+#include "QC_pauliY.h"\r
+#include "QC_pauliZ.h"\r
+#include "QC_rot.h"\r
+#include "QC_swap.h"\r
diff --git a/calcunits/QC_ccnot.cpp b/calcunits/QC_ccnot.cpp
new file mode 100644 (file)
index 0000000..2c42649
--- /dev/null
@@ -0,0 +1,93 @@
+//---------------------------------------------------------------------------
+#include "QC_ccnot.h"
+//---------------------------------------------------------------------------
+/**
+ * Constructor
+**/
+QC_ccnot::QC_ccnot(int _target, int _control1, int _control2) : QCalcUnit() {
+    TargetBit = _target;
+    ControlBit1 = _control1;
+    ControlBit2 = _control2;
+}
+//---------------------------------------------------------------------------
+/**
+ *
+**/
+void
+QC_ccnot::calc(int target, int control1, int control2,
+               double R[], double I[], int NumberOfBits) {
+// Sort Bits to reglar order of bit number
+    int Bit0 = target;
+    int Bit1 = control1;
+    int Bit2 = control2;
+    if (Bit0 > Bit1) swap(Bit0, Bit1);
+    if (Bit1 > Bit2) swap(Bit1, Bit2);
+    if (Bit0 > Bit1) swap(Bit0, Bit1);
+
+    unsigned int states = 1 << (NumberOfBits - 3);
+
+    for (unsigned int i = 0; i < states; i++) {
+        unsigned int ix = i;
+        ix = insert1(ix,Bit0);
+        ix = insert1(ix,Bit1);
+        ix = insert1(ix,Bit2);
+
+        unsigned int ix_1 = ix;
+        unsigned int ix_0 = ix & ~(1 << target); //Set TargetBit 0
+        swap(R[ix_0], R[ix_1]);
+        swap(I[ix_0], I[ix_1]);
+    }
+
+}
+//---------------------------------------------------------------------------
+void
+QC_ccnot::Calc(QBits *qBits) {
+    double *R = qBits->GetBitsR();//Real Part
+    double *I = qBits->GetBitsI();//Imaginary Part
+    int N = qBits->GetNumberOfQBits();
+
+    QC_ccnot::calc(TargetBit, ControlBit1, ControlBit2, R, I, N);
+}
+//---------------------------------------------------------------------------
+#ifdef __USE__MPI
+void
+QC_ccnot::calcmpi(int t1, int c1, int c2, double R[], double I[], int N) {
+
+    // Sort Bits to reglar order of bit number
+    int Bit0 = t1;
+    int Bit1 = c1;
+    int Bit2 = c2;
+    if (Bit0 > Bit1) {
+        swap(Bit0, Bit1);
+    }
+    if (Bit1 > Bit2) {
+        swap(Bit1, Bit2);
+    }
+    if (Bit0 > Bit1) {
+        swap(Bit0, Bit1);
+    }
+
+    double r0 = 0.0;
+    double i0 = 0.0;
+    double r1 = 0.0;
+    double i1 = 0.0;
+    unsigned int ix0, ix1;
+
+    for (int i = 0; i < (1 << (N - 3)); i++) {
+        unsigned int ix = i;
+        ix = insert1(ix,Bit0);
+        ix = insert1(ix,Bit1);
+        ix = insert1(ix,Bit2);
+        unsigned int ix_1 = ix;
+        unsigned int ix_0 = ix & ~(1 << t1); //Set TargetBit 0
+        bool bstore = setup(R, I, ix0, ix1, r0, i0, r1, i1);
+        if (bstore) {
+            swap(r0, r1);
+            swap(i0, i1);
+            // Store:
+            store(R, I, ix0, ix1, r0, i0, r1, i1);
+        }
+    }
+}
+#endif
+//---------------------------------------------------------------------------
diff --git a/calcunits/QC_ccnot.h b/calcunits/QC_ccnot.h
new file mode 100644 (file)
index 0000000..b84ea76
--- /dev/null
@@ -0,0 +1,31 @@
+//---------------------------------------------------------------------------
+// Cotroled controled not gate
+//---------------------------------------------------------------------------
+#ifndef QC_ccnotH
+#define QC_ccnotH
+
+#include "QCalcUnit.h"
+//---------------------------------------------------------------------------
+class QC_ccnot : public QCalcUnit
+{
+private:
+    int ControlBit1;
+    int ControlBit2;
+    int TargetBit;
+
+public:
+
+    QC_ccnot(int TargetBit,int ControllBit1, int ControlBit2);
+
+    static  void calc(int t, int c1, int c2, double R[], double I[], int bits);
+    virtual void Calc(QBits *QBits);
+    virtual std::string GetName(void) const {
+        return "Toffoli";
+    }
+
+
+#ifdef __USE__MPI
+    static void calcmpi(int t1, int c1, int c2, double R[], double I[], int N);
+#endif
+};
+#endif
diff --git a/calcunits/QC_cnot.cpp b/calcunits/QC_cnot.cpp
new file mode 100644 (file)
index 0000000..3e83e63
--- /dev/null
@@ -0,0 +1,79 @@
+//---------------------------------------------------------------------------
+//  Controled-not gate
+//---------------------------------------------------------------------------
+#include "QC_cnot.h"
+//---------------------------------------------------------------------------
+/**
+ *  Constructor
+ */
+QC_cnot::QC_cnot(int _TargetBit,int _ControlBit) : QCalcUnit() {
+    TargetBit  = _TargetBit;
+    ControlBit = _ControlBit;
+}
+//---------------------------------------------------------------------------
+/**
+ *  Calculation
+ */
+void QC_cnot::calc(int Target, int Control,
+                   double BitsR[], double BitsI[], int NumberOfBits) {
+    unsigned int states = (1 << (NumberOfBits - 2));
+
+    // Sort BitsNumber to regular order
+    int Bit0 = Target;
+    int Bit1 = Control;
+    if (Bit0 > Bit1) {
+        swap(Bit0, Bit1);
+    }
+
+    for (unsigned int i = 0; i < states; i++) {
+        unsigned int ix1 = QCalcUnit::insert1(i,   Bit0);
+        ix1 = QCalcUnit::insert1(ix1, Bit1);
+        unsigned int ix0 = ix1 & ~(1 << Target);
+
+        swap(BitsR[ix0], BitsR[ix1]);
+        swap(BitsI[ix0], BitsI[ix1]);
+    }
+}
+//---------------------------------------------------------------------------
+void
+QC_cnot::Calc(QBits *qBits) {
+    int N = qBits->GetNumberOfQBits();
+    double *R = qBits->GetBitsR();//Real Part
+    double *I = qBits->GetBitsI();//Imaginary Part
+
+    QC_cnot::calc(TargetBit, ControlBit, R, I, N);
+}
+//---------------------------------------------------------------------------
+#ifdef __USE__MPI
+void
+QC_cnot::calcmpi(int t1, int c1, double R[], double I[], int N) {
+    double r0 = 0.0;
+    double i0 = 0.0;
+    double r1 = 0.0;
+    double i1 = 0.0;
+    unsigned int ix0, ix1;
+
+    // Sort BitsNumber to regular order
+    int Bit0 = t1;
+    int Bit1 = c1;
+    if (Bit0 > Bit1) {
+        swap(Bit0, Bit1);
+    }
+
+    for (int i = 0; i < (1 << (N - 2)); i++) {
+        // Obtain indices of state:
+        unsigned int ix1 = QCalcUnit::insert1(i,   Bit0);
+        ix1 = QCalcUnit::insert1(ix1, Bit1);
+        unsigned int ix0 = ix1 & ~(1 << t1);
+
+        bool bstore = setup(R, I, ix0, ix1, r0, i0, r1, i1);
+        if (bstore) {
+            swap(r0, r1);
+            swap(i0, i1);
+            // Store:
+            store(R, I, ix0, ix1, r0, i0, r1, i1);
+        }
+    }
+}
+#endif
+//---------------------------------------------------------------------------
diff --git a/calcunits/QC_cnot.h b/calcunits/QC_cnot.h
new file mode 100644 (file)
index 0000000..de4a730
--- /dev/null
@@ -0,0 +1,31 @@
+//---------------------------------------------------------------------------
+// Controlled Not gate
+//---------------------------------------------------------------------------
+#ifndef QC_cnotH
+#define QC_cnotH
+//---------------------------------------------------------------------------
+#include "QCalcUnit.h"
+#include "QBits.h"
+//---------------------------------------------------------------------------
+class QC_cnot : public QCalcUnit
+{
+private:
+    int ControlBit;
+    int TargetBit;
+
+public:
+    QC_cnot(int TargetBit,int ControllBit);
+    static void calc(int t, int c, double R[], double I[], int N);
+    virtual void Calc(QBits *QBits);
+    virtual std::string GetName(void) const {
+        return "Controlled Not";
+    }
+
+
+#ifdef __USE__MPI
+    static void calcmpi(int t1, int c1, double R[], double I[], int N);
+#endif
+
+};
+//---------------------------------------------------------------------------
+#endif
diff --git a/calcunits/QC_crot.cpp b/calcunits/QC_crot.cpp
new file mode 100644 (file)
index 0000000..856cba6
--- /dev/null
@@ -0,0 +1,89 @@
+//---------------------------------------------------------------------------
+// Controlled Rotate Gate
+//---------------------------------------------------------------------------
+#include <cmath>
+#include <math.h>
+#include "QC_crot.h"
+//---------------------------------------------------------------------------
+/**
+ * Constructor
+ */
+QC_crot::QC_crot(int _TargetBit,int _ControlBit, double degree) : QCalcUnit() {
+    TargetBit = _TargetBit;
+    ControlBit = _ControlBit;
+    Theta = M_PI * degree / 180.0;
+}
+//---------------------------------------------------------------------------
+/**
+ * Calculation
+ */
+void
+QC_crot::calc(int Target, int Control, double theta,
+              double R[], double I[], int NumberOfBits) {
+    unsigned int states = 1<< (NumberOfBits - 2);
+
+    int Bit0 = Target;
+    int Bit1 = Control;
+    if (Bit0 > Bit1) swap(Bit0, Bit1);
+
+    const double c     = std::cos(theta);
+    const double s     = std::sin(theta);
+
+    double r1, i1;
+    for (unsigned int i = 0; i < states; i++) {
+        unsigned int ix1 = QCalcUnit::insert1(i,   Bit0);
+        ix1 = QCalcUnit::insert1(ix1, Bit1);
+        double r1 = R[ix1];
+        double i1 = I[ix1];
+
+        R[ix1] =  c*r1 - s*i1;
+        I[ix1] =  s*r1 + c*i1;
+    }
+}
+//---------------------------------------------------------------------------
+void
+QC_crot::Calc(QBits *qBits) {
+    int N = qBits->GetNumberOfQBits();
+    double *R = qBits->GetBitsR();//Real Part
+    double *I = qBits->GetBitsI();//Imaginary Part
+
+    QC_crot::calc(TargetBit, ControlBit, Theta, R, I, N);
+}
+//---------------------------------------------------------------------------
+#ifdef __USE__MPI
+void
+QC_crot::calcmpi(int t1, int c1, double theta, double R[], double I[], int N) {
+    const double c     = std::cos(theta);
+    const double s     = std::sin(theta);
+    double r0 = 0.0;
+    double i0 = 0.0;
+    double r1 = 0.0;
+    double i1 = 0.0;
+    unsigned int ix0, ix1;
+
+    // Sort BitsNumber to regular order
+    int Bit0 = t1;
+    int Bit1 = c1;
+    if (Bit0 > Bit1) {
+        swap(Bit0, Bit1);
+    }
+
+    for (int i = 0; i < (1 << (N - 2)); i++) {
+        // Obtain indices of state:
+        unsigned int ix1 = QCalcUnit::insert1(i,   Bit0);
+        ix1 = QCalcUnit::insert1(ix1, Bit1);
+        unsigned int ix0 = ix1 & ~(1 << t1);
+
+        bool bstore = setup(R, I, ix0, ix1, r0, i0, r1, i1);
+        if (bstore) {
+            double nr0 = r0;
+            double ni0 = i0;
+            double nr1 = c*r1 - s*i1;
+            double ni1 = s*r1 + c*i1;
+            // Store:
+            store(R, I, ix0, ix1, nr0, ni0, nr1, ni1);
+        }
+    }
+}
+#endif
+//---------------------------------------------------------------------------
diff --git a/calcunits/QC_crot.h b/calcunits/QC_crot.h
new file mode 100644 (file)
index 0000000..d510db2
--- /dev/null
@@ -0,0 +1,32 @@
+//---------------------------------------------------------------------------
+// Controlled Rotate Gate
+//---------------------------------------------------------------------------
+#ifndef QC_crotH
+#define QC_crotH
+//---------------------------------------------------------------------------
+#include "QCalcUnit.h"
+#include "QBits.h"
+//---------------------------------------------------------------------------
+
+class QC_crot : public QCalcUnit
+{
+private:
+    int ControlBit;
+    int TargetBit;
+    double Theta;// Degree of rotation(Radian)
+public:
+
+    QC_crot(int _TargetBit,int _ControllBit,double degree);
+    static void calc(int t, int c, double theta, double R[], double I[], int N);
+    virtual void Calc(QBits *QBits);
+    virtual std::string GetName(void) const {
+        return "Controlled Rot";
+    }
+
+#ifdef __USE__MPI
+    static void calcmpi(int t1, int c1, double theta, double R[], double I[], int N);
+#endif
+
+};
+//---------------------------------------------------------------------------
+#endif
diff --git a/calcunits/QC_hadamard.cpp b/calcunits/QC_hadamard.cpp
new file mode 100644 (file)
index 0000000..b00c486
--- /dev/null
@@ -0,0 +1,78 @@
+//---------------------------------------------------------------------------
+//  Hadamard gate
+//---------------------------------------------------------------------------
+#include <cmath>
+#include "QC_hadamard.h"
+//---------------------------------------------------------------------------
+/**
+ *  Constructor
+ */
+QC_hadamard::QC_hadamard(int _Target) : QCalcUnit() {
+    Target = _Target;
+}
+//---------------------------------------------------------------------------
+/**
+ *  Calculate
+ */
+void QC_hadamard::calc(int target, double R[], double I[], int NumberOfBits) {
+
+    unsigned int state = 1<< (NumberOfBits - 1);
+    const double sq2 = 1.0 / std::sqrt(2.0);
+
+    double r0,r1,i0,i1;
+    for (unsigned int i=0;i<state;i++) {
+        unsigned int ix0 = insert0(i,target);
+        unsigned int ix1 = insert1(i,target);
+
+        //Hadamard
+        r0 = R[ix0];
+        i0 = I[ix0];
+        r1 = R[ix1];
+        i1 = I[ix1];
+
+        R[ix0] = sq2*(r1+r0);
+        I[ix0] = sq2*(i1+i0);
+
+        R[ix1] = sq2*(-r1+r0);
+        I[ix1] = sq2*(-i1+i0);
+    }
+}
+//---------------------------------------------------------------------------
+void
+QC_hadamard::Calc(QBits *qBits) {
+    int N = qBits->GetNumberOfQBits();
+    double *R = qBits->GetBitsR();//Real Part
+    double *I = qBits->GetBitsI();//Imaginary Part
+
+    QC_hadamard::calc(Target, R, I, N);
+}
+//---------------------------------------------------------------------------
+#ifdef __USE__MPI
+void
+QC_hadamard::calcmpi(int t1, double R[], double I[], int N) {
+    double r0 = 0.0;
+    double i0 = 0.0;
+    double r1 = 0.0;
+    double i1 = 0.0;
+    unsigned int ix0, ix1;
+    const double sq2 = 1.0 / std::sqrt(2.0);
+
+    for (int i = 0; i < (1 << (N - 1)); i++) {
+        // Obtain indices of state:
+        ix0 = QCalcUnit::insert0(i, t1);
+        ix1 = QCalcUnit::insert1(i, t1);
+
+        bool bstore = setup(R, I, ix0, ix1, r0, i0, r1, i1);
+        if (bstore) {
+            double nr0 = sq2*(r1+r0);
+            double ni0 = sq2*(i1+i0);
+            double nr1 = sq2*(-r1+r0);
+            double ni1 = sq2*(-i1+i0);
+            // Store:
+            store(R, I, ix0, ix1, nr0, ni0, nr1, ni1);
+        }
+    }
+}
+#endif
+//---------------------------------------------------------------------------
+
diff --git a/calcunits/QC_hadamard.h b/calcunits/QC_hadamard.h
new file mode 100644 (file)
index 0000000..6b9cc7f
--- /dev/null
@@ -0,0 +1,30 @@
+//---------------------------------------------------------------------------
+// Hadamard gate
+//---------------------------------------------------------------------------
+#ifndef QC_hadamardH
+#define QC_hadamardH
+//---------------------------------------------------------------------------
+#include "QCalcUnit.h"
+//---------------------------------------------------------------------------
+
+class QC_hadamard : public QCalcUnit
+{
+private:
+    int Target;//Target bit of calculation
+
+public:
+
+    QC_hadamard(int _Target);// Constructor
+    static void calc(int target, double R[], double I[], int N);
+    virtual void Calc(QBits *QBits);// Calclation
+    virtual std::string GetName(void) const {
+        return "Hadamard";
+    }
+
+#ifdef __USE__MPI
+    static void calcmpi(int t1, double R[], double I[], int N);
+#endif
+
+};
+//---------------------------------------------------------------------------
+#endif
diff --git a/calcunits/QC_measure.cpp b/calcunits/QC_measure.cpp
new file mode 100644 (file)
index 0000000..1c3e567
--- /dev/null
@@ -0,0 +1,28 @@
+//---------------------------------------------------------------------------
+//  Measurement gate
+//---------------------------------------------------------------------------
+#include "QC_measure.h"
+//---------------------------------------------------------------------------
+/**
+ * Constructor
+ */
+QC_measure::QC_measure(const int _Target) : QCalcUnit() {
+    Target = _Target;
+}
+//---------------------------------------------------------------------------
+/**
+ * Calculation
+ */
+void
+QC_measure::calc(int target, double BitsR[], double BitsI[], int NumberOfBits) {
+}
+//---------------------------------------------------------------------------
+void QC_measure::Calc(QBits *qBits) {
+    qBits->Measure(Target);
+}
+//---------------------------------------------------------------------------
+#ifdef __USE__MPI
+void QC_measure::calcmpi(int t1, double R[], double I[], int N) {
+}
+#endif
+//---------------------------------------------------------------------------
diff --git a/calcunits/QC_measure.h b/calcunits/QC_measure.h
new file mode 100644 (file)
index 0000000..d165d09
--- /dev/null
@@ -0,0 +1,25 @@
+//---------------------------------------------------------------------------
+// Measurement
+//---------------------------------------------------------------------------
+#ifndef QC_measureH
+#define QC_measureH
+//---------------------------------------------------------------------------
+#include "QCalcUnit.h"
+//---------------------------------------------------------------------------
+class QC_measure : public QCalcUnit
+{
+private:
+    int Target;
+public:
+    QC_measure(const int _Target);
+    static void calc(int target, double BitsR[], double BitsI[], int bits);
+    virtual void Calc(QBits *qBits);
+    virtual std::string GetName(void) const {
+        return "Measure";
+    }
+#ifdef __USE__MPI
+    static void calcmpi(int t1, double R[], double I[], int N);
+#endif
+};
+//---------------------------------------------------------------------------
+#endif
diff --git a/calcunits/QC_not.cpp b/calcunits/QC_not.cpp
new file mode 100644 (file)
index 0000000..a24214f
--- /dev/null
@@ -0,0 +1,60 @@
+//---------------------------------------------------------------------------
+//  Not gate
+//---------------------------------------------------------------------------
+#include "QC_not.h"
+//---------------------------------------------------------------------------
+/**
+ * Constructor
+ */
+QC_not::QC_not(const int _Target) : QCalcUnit() {
+    Target = _Target;
+}
+//---------------------------------------------------------------------------
+/**
+ * Calculation
+ */
+void QC_not::calc(int target, double BitsR[], double BitsI[], int NumberOfBits) {
+    unsigned int states = (1 << (NumberOfBits - 1));
+    for (unsigned int i = 0; i < states; i++) {
+        unsigned int ix0 = QCalcUnit::insert1(i, target);
+        unsigned int ix1 = QCalcUnit::insert0(i, target);
+        swap(BitsR[ix0], BitsR[ix1]);
+        swap(BitsI[ix0], BitsI[ix1]);
+    }
+}
+//---------------------------------------------------------------------------
+void
+QC_not::Calc(QBits *qBits) {
+    double *R = qBits->GetBitsR();//Real Part
+    double *I = qBits->GetBitsI();//Imaginary Part
+    int N = qBits->GetNumberOfQBits();
+
+    QC_not::calc(Target, R, I, N);
+}
+//---------------------------------------------------------------------------
+#ifdef __USE__MPI
+void
+QC_not::calcmpi(int t1, double R[], double I[], int N) {
+    double r0 = 0.0;
+    double i0 = 0.0;
+    double r1 = 0.0;
+    double i1 = 0.0;
+    unsigned int ix0, ix1;
+
+    for (int i = 0; i < (1 << (N - 1)); i++) {
+        // Obtain indices of state:
+        ix0 = QCalcUnit::insert0(i, t1);
+        ix1 = QCalcUnit::insert1(i, t1);
+
+        bool bstore = setup(R, I, ix0, ix1, r0, i0, r1, i1);
+        if (bstore) {
+            // Calc:
+            swap(r0, r1);
+            swap(i0, i1);
+            // Store:
+            store(R, I, ix0, ix1, r0, i0, r1, i1);
+        }
+    }
+}
+#endif
+//---------------------------------------------------------------------------
diff --git a/calcunits/QC_not.h b/calcunits/QC_not.h
new file mode 100644 (file)
index 0000000..31d6b57
--- /dev/null
@@ -0,0 +1,25 @@
+//---------------------------------------------------------------------------
+// Not Gate
+//---------------------------------------------------------------------------
+#ifndef QC_notH
+#define QC_notH
+//---------------------------------------------------------------------------
+#include "QCalcUnit.h"
+//---------------------------------------------------------------------------
+class QC_not : public QCalcUnit
+{
+private:
+    int Target;
+public:
+    QC_not(const int _Target);
+    static void calc(int target, double BitsR[], double BitsI[], int bits);
+    virtual void Calc(QBits *qBits);
+    virtual std::string GetName(void) const {
+        return "Not";
+    }
+#ifdef __USE__MPI
+    static void calcmpi(int t1, double R[], double I[], int N);
+#endif
+};
+//---------------------------------------------------------------------------
+#endif
diff --git a/calcunits/QC_pauliX.cpp b/calcunits/QC_pauliX.cpp
new file mode 100644 (file)
index 0000000..11db859
--- /dev/null
@@ -0,0 +1,35 @@
+//---------------------------------------------------------------------------
+#include "QC_pauliX.h"
+#include "QC_not.h"
+//---------------------------------------------------------------------------
+/**
+ *  Constructor
+ */
+QC_pauliX::QC_pauliX(int _Target) : QCalcUnit() {
+    Target = _Target;
+}
+//---------------------------------------------------------------------------
+/**
+ *  Calculate
+ */
+void
+QC_pauliX::calc(int target, double R[], double I[], int NumberOfBits) {
+    QC_not::calc(target, R, I, NumberOfBits);
+}
+//---------------------------------------------------------------------------
+void
+QC_pauliX::Calc(QBits *qBits) {
+    int N = qBits->GetNumberOfQBits();
+    double *R = qBits->GetBitsR();//Real Part
+    double *I = qBits->GetBitsI();//Imaginary Part
+
+    QC_pauliX::calc(Target, R, I, N);
+}
+//---------------------------------------------------------------------------
+#ifdef __USE__MPI
+void
+QC_pauliX::calcmpi(int t1, double R[], double I[], int N) {
+    QC_not::calcmpi(t1,R,I,N);
+}
+#endif
+//---------------------------------------------------------------------------
diff --git a/calcunits/QC_pauliX.h b/calcunits/QC_pauliX.h
new file mode 100644 (file)
index 0000000..6611893
--- /dev/null
@@ -0,0 +1,32 @@
+//---------------------------------------------------------------------------
+// Pauli X gate
+//---------------------------------------------------------------------------
+#ifndef QC_pauliXH
+#define QC_pauliXH
+//---------------------------------------------------------------------------
+//---------------------------------------------------------------------------
+#include "QCalcUnit.h"
+//---------------------------------------------------------------------------
+
+class QC_pauliX : public QCalcUnit
+{
+private:
+    int Target;//Target bit of calculation
+
+public:
+
+    QC_pauliX(int _Target);// Constructor
+    static void calc(int target, double R[], double I[], int N);
+    virtual void Calc(QBits *QBits);// Calclation
+    virtual std::string GetName(void) const {
+        return "Pauli-X";
+    }
+
+#ifdef __USE__MPI
+    static void calcmpi(int t1, double R[], double I[], int N);
+#endif
+
+};
+//---------------------------------------------------------------------------
+#endif
+
diff --git a/calcunits/QC_pauliY.cpp b/calcunits/QC_pauliY.cpp
new file mode 100644 (file)
index 0000000..26ba00a
--- /dev/null
@@ -0,0 +1,74 @@
+//---------------------------------------------------------------------------
+//  Pauli Y gate
+//---------------------------------------------------------------------------
+#include "QC_pauliY.h"
+//---------------------------------------------------------------------------
+/**
+ *  Constructor
+ */
+QC_pauliY::QC_pauliY(int _Target) : QCalcUnit() {
+    Target = _Target;
+}
+//---------------------------------------------------------------------------
+/**
+ *  Calculate
+ */
+void
+QC_pauliY::calc(int target, double R[], double I[], int NumberOfBits) {
+    unsigned int state = 1<< (NumberOfBits - 1);
+
+    double r0,r1,i0,i1;
+    for (unsigned int i=0;i<state;i++) {
+        unsigned int ix0 = insert0(i,target);
+        unsigned int ix1 = insert1(i,target);
+
+        //pauli Y
+        r0 = R[ix0];
+        i0 = I[ix0];
+        r1 = R[ix1];
+        i1 = I[ix1];
+
+        R[ix0] = i1;
+        I[ix0] = -r1;
+        R[ix1] = -i0;
+        I[ix1] = r0;
+    }
+}
+//---------------------------------------------------------------------------
+void QC_pauliY::Calc(QBits *qBits)
+{
+    int N = qBits->GetNumberOfQBits();
+    double *R = qBits->GetBitsR();//Real Part
+    double *I = qBits->GetBitsI();//Imaginary Part
+
+    QC_pauliY::calc(Target, R, I, N);
+}
+//---------------------------------------------------------------------------
+#ifdef __USE__MPI
+void
+QC_pauliY::calcmpi(int t1, double R[], double I[], int N) {
+    double r0 = 0.0;
+    double i0 = 0.0;
+    double r1 = 0.0;
+    double i1 = 0.0;
+    unsigned int ix0, ix1;
+
+    for (int i = 0; i < (1 << (N - 1)); i++)
+    {
+        // Obtain indices of state:
+        ix0 = QCalcUnit::insert0(i, t1);
+        ix1 = QCalcUnit::insert1(i, t1);
+
+        bool bstore = setup(R, I, ix0, ix1, r0, i0, r1, i1);
+        if (bstore) {
+            double nr0 = i1;
+            double ni0 = -r1;
+            double nr1 = -i0;
+            double ni1 = r0;
+            // Store:
+            store(R, I, ix0, ix1, nr0, ni0, nr1, ni1);
+        }
+    }
+}
+#endif
+//---------------------------------------------------------------------------
diff --git a/calcunits/QC_pauliY.h b/calcunits/QC_pauliY.h
new file mode 100644 (file)
index 0000000..7d1f617
--- /dev/null
@@ -0,0 +1,32 @@
+//---------------------------------------------------------------------------
+// Pauli Y gate
+//---------------------------------------------------------------------------
+//---------------------------------------------------------------------------
+#ifndef QC_pauliYH
+#define QC_pauliYH
+//---------------------------------------------------------------------------
+#include "QCalcUnit.h"
+//---------------------------------------------------------------------------
+
+class QC_pauliY : public QCalcUnit
+{
+private:
+    int Target;//Target bit of calculation
+
+public:
+
+    QC_pauliY(int _Target);// Constructor
+    static void calc(int target, double R[], double I[], int N);
+    virtual void Calc(QBits *QBits);// Calclation
+    virtual std::string GetName(void) const {
+        return "Pauli-Y";
+    }
+
+#ifdef __USE__MPI
+    static void calcmpi(int t1, double R[], double I[], int N);
+#endif
+
+};
+//---------------------------------------------------------------------------
+#endif
+
diff --git a/calcunits/QC_pauliZ.cpp b/calcunits/QC_pauliZ.cpp
new file mode 100644 (file)
index 0000000..7b777ae
--- /dev/null
@@ -0,0 +1,66 @@
+//---------------------------------------------------------------------------
+// Pauli Z gate
+//---------------------------------------------------------------------------
+#include "QC_pauliZ.h"
+//---------------------------------------------------------------------------
+/**
+ *  Constructor
+ */
+QC_pauliZ::QC_pauliZ(int _Target) : QCalcUnit() {
+    Target = _Target;
+}
+//---------------------------------------------------------------------------
+/**
+ *  Calculate
+ */
+void
+QC_pauliZ::calc(int target, double R[], double I[], int NumberOfBits) {
+
+    unsigned int state = 1<< (NumberOfBits - 1);
+    for (unsigned int i=0;i<state;i++) {
+        unsigned int ix1 = insert1(i,target);
+
+        //Pauli Z
+
+        R[ix1] = -R[ix1];
+        I[ix1] = -I[ix1];
+    }
+}
+//---------------------------------------------------------------------------
+void
+QC_pauliZ::Calc(QBits *qBits) {
+    int N = qBits->GetNumberOfQBits();
+    double *R = qBits->GetBitsR();//Real Part
+    double *I = qBits->GetBitsI();//Imaginary Part
+
+    QC_pauliZ::calc(Target, R, I, N);
+}
+//---------------------------------------------------------------------------
+#ifdef __USE__MPI
+void
+QC_pauliZ::calcmpi(int t1, double R[], double I[], int N) {
+    double r0 = 0.0;
+    double i0 = 0.0;
+    double r1 = 0.0;
+    double i1 = 0.0;
+    unsigned int ix0, ix1;
+
+    for (int i = 0; i < (1 << (N - 1)); i++) {
+        // Obtain indices of state:
+        ix0 = QCalcUnit::insert0(i, t1);
+        ix1 = QCalcUnit::insert1(i, t1);
+
+        bool bstore = setup(R, I, ix0, ix1, r0, i0, r1, i1);
+        if (bstore) {
+            double nr0 = r0;
+            double ni0 = i0;
+            double nr1 = -r1;
+            double ni1 = -i1;
+            // Store:
+            store(R, I, ix0, ix1, nr0, ni0, nr1, ni1);
+        }
+    }
+}
+#endif
+//---------------------------------------------------------------------------
+
diff --git a/calcunits/QC_pauliZ.h b/calcunits/QC_pauliZ.h
new file mode 100644 (file)
index 0000000..5d6b164
--- /dev/null
@@ -0,0 +1,32 @@
+//---------------------------------------------------------------------------
+// Pauli Z gate
+//---------------------------------------------------------------------------
+#ifndef QC_pauliZH
+#define QC_pauliZH
+//---------------------------------------------------------------------------
+//---------------------------------------------------------------------------
+#include "QCalcUnit.h"
+//---------------------------------------------------------------------------
+
+class QC_pauliZ : public QCalcUnit
+{
+private:
+    int Target;//Target bit of calculation
+
+public:
+
+    QC_pauliZ(int _Target);// Constructor
+    static void calc(int target, double R[], double I[], int N);
+    virtual void Calc(QBits *QBits);// Calclation
+    virtual std::string GetName(void) const {
+        return "Pauli-Z";
+    }
+
+#ifdef __USE__MPI
+    static void calcmpi(int t1, double R[], double I[], int N);
+#endif
+
+};
+//---------------------------------------------------------------------------
+
+#endif
diff --git a/calcunits/QC_rot.cpp b/calcunits/QC_rot.cpp
new file mode 100644 (file)
index 0000000..e500d49
--- /dev/null
@@ -0,0 +1,73 @@
+//---------------------------------------------------------------------------\r
+// Rotate Gate\r
+//---------------------------------------------------------------------------\r
+#include <cmath>\r
+#include <math.h>\r
+#include "QC_rot.h"\r
+//---------------------------------------------------------------------------\r
+/**\r
+ *\r
+ */\r
+QC_rot::QC_rot(int _TargetBit,double degree) : QCalcUnit() {\r
+    TargetBit = _TargetBit;\r
+    Theta = M_PI * degree / 180.0;\r
+}\r
+//---------------------------------------------------------------------------\r
+/**\r
+ * Calculation\r
+ */\r
+void\r
+QC_rot::calc(int target, double theta,\r
+             double R[], double I[], int NumberOfBits) {\r
+    const double c     = std::cos(theta);\r
+    const double s     = std::sin(theta);\r
+    double r1, i1;\r
+    unsigned int states = (1 << (NumberOfBits - 1));\r
+    for (unsigned int i = 0; i < states; i++) {\r
+        unsigned int ix1 = QCalcUnit::insert1(i, target);\r
+        double r1 = R[ix1];\r
+        double i1 = I[ix1];\r
+\r
+        R[ix1] =  c*r1 - s*i1;\r
+        I[ix1] =  s*r1 + c*i1;\r
+    }\r
+}\r
+//---------------------------------------------------------------------------\r
+void QC_rot::Calc(QBits *qBits)\r
+{\r
+    int N = qBits->GetNumberOfQBits();\r
+    double *R = qBits->GetBitsR();//Real Part\r
+    double *I = qBits->GetBitsI();//Imaginary Part\r
+    QC_rot::calc(TargetBit, Theta, R, I, N);\r
+}\r
+//---------------------------------------------------------------------------\r
+#ifdef __USE__MPI\r
+void\r
+QC_rot::calcmpi(int t1, double theta, double R[], double I[], int N) {\r
+    const double c     = std::cos(theta);\r
+    const double s     = std::sin(theta);\r
+    double r0 = 0.0;\r
+    double i0 = 0.0;\r
+    double r1 = 0.0;\r
+    double i1 = 0.0;\r
+    unsigned int ix0, ix1;\r
+\r
+    for (int i = 0; i < (1 << (N - 1)); i++) {\r
+        // Obtain indices of state:\r
+        ix0 = QCalcUnit::insert0(i, t1);\r
+        ix1 = QCalcUnit::insert1(i, t1);\r
+\r
+        bool bstore = setup(R, I, ix0, ix1, r0, i0, r1, i1);\r
+\r
+        if (bstore) {\r
+            double nr0 = r0;\r
+            double ni0 = i0;\r
+            double nr1 = c*r1 - s*i1;\r
+            double ni1 = s*r1 + c*i1;\r
+            // Store:\r
+            store(R, I, ix0, ix1, nr0, ni0, nr1, ni1);\r
+        }\r
+    }\r
+}\r
+#endif\r
+//---------------------------------------------------------------------------\r
diff --git a/calcunits/QC_rot.h b/calcunits/QC_rot.h
new file mode 100644 (file)
index 0000000..77c5b87
--- /dev/null
@@ -0,0 +1,30 @@
+//---------------------------------------------------------------------------\r
+// Rotate Gate\r
+//---------------------------------------------------------------------------\r
+#ifndef QC_rotH\r
+#define QC_rotH\r
+//---------------------------------------------------------------------------\r
+#include "QCalcUnit.h"\r
+#include "QBits.h"\r
+//---------------------------------------------------------------------------\r
+\r
+class QC_rot : public QCalcUnit\r
+{\r
+private:\r
+    int TargetBit;\r
+    double Theta;// Degree of rotation(Radian)\r
+public:\r
+\r
+    QC_rot(int _TargetBit,double degree);\r
+    static void calc(int target, double theta, double R[], double I[], int N);\r
+    virtual void Calc(QBits *QBits);\r
+    virtual std::string GetName(void) const {\r
+        return "Rot";\r
+    }\r
+\r
+#ifdef __USE__MPI\r
+    static void calcmpi(int t1, double theta, double R[], double I[], int N);\r
+#endif\r
+};\r
+//---------------------------------------------------------------------------\r
+#endif\r
diff --git a/calcunits/QC_swap.cpp b/calcunits/QC_swap.cpp
new file mode 100644 (file)
index 0000000..ee9fb01
--- /dev/null
@@ -0,0 +1,87 @@
+//---------------------------------------------------------------------------
+// Swap gate
+//---------------------------------------------------------------------------
+#include "QC_swap.h"
+//---------------------------------------------------------------------------
+
+/**
+ *  Constructor
+ */
+QC_swap::QC_swap(int target1,int target2) : QCalcUnit() {
+    TargetBit1 = target1;
+    TargetBit2 = target2;
+}
+//---------------------------------------------------------------------------
+/**
+ *  Calculation
+ */
+void QC_swap::calc(int target1, int target2,
+                   double BitsR[], double BitsI[], int NumberOfBits) {
+    unsigned int states = (1 << (NumberOfBits - 2));
+    // Sort Bits to regular order of bit index
+    int Bit0 = target1;
+    int Bit1 = target2;
+    if (Bit0 > Bit1) {
+        QCalcUnit::swap(Bit0, Bit1);
+    }
+
+    for (unsigned int i = 0; i < states; i++) {
+        unsigned int ix1 = insert1(i,   Bit0);
+        ix1 = insert0(ix1, Bit1);
+        unsigned int ix2 = insert0(i,   Bit0);
+        ix2 = insert1(ix2, Bit1);
+
+        QCalcUnit::swap(BitsR[ix1], BitsR[ix2]);
+        QCalcUnit::swap(BitsI[ix1], BitsI[ix2]);
+    }
+}
+//---------------------------------------------------------------------------
+void QC_swap::Calc(QBits *qBits)
+{
+    int N = qBits->GetNumberOfQBits();
+    double *R = qBits->GetBitsR();
+    double *I = qBits->GetBitsI();
+
+    QC_swap::calc(TargetBit1, TargetBit2, R, I, N);
+}
+//---------------------------------------------------------------------------
+#ifdef __USE__MPI
+void
+QC_swap::calcmpi(int t1, int t2, double R[], double I[], int N) {
+    // Sort Bits to regular order of bit index
+    int Bit0 = t1;
+    int Bit1 = t2;
+    if (Bit0 > Bit1) {
+        QCalcUnit::swap(Bit0, Bit1);
+    }
+
+    double r0 = 0.0;
+    double i0 = 0.0;
+    double r1 = 0.0;
+    double i1 = 0.0;
+    unsigned int ix0, ix1;
+
+    printf("Swap Gate has not been implemented yet.\n");
+//TODO:
+    /*
+      for (int i = 0; i < (1 << (N - 2)); i++)
+        {
+          // Obtain indices of state:
+          unsigned int ix1 = insert1(i,   Bit0);
+                       ix1 = insert0(ix1, Bit1);
+          unsigned int ix2 = insert0(i,   Bit0);
+                       ix2 = insert1(ix2, Bit1);
+
+          bool bstore = setup(R, I, ix0, ix1, r0, i0, r1, i1);
+          if (bstore) {
+            // Calc:
+            QCalcUnit::swap(r0, r1);
+            QCalcUnit::swap(i0, i1);
+            // Store:
+            store(R, I, ix0, ix1, r0, i0, r1, i1);
+          }
+        }
+    */
+}
+#endif
+//---------------------------------------------------------------------------
diff --git a/calcunits/QC_swap.h b/calcunits/QC_swap.h
new file mode 100644 (file)
index 0000000..0a0d645
--- /dev/null
@@ -0,0 +1,28 @@
+//---------------------------------------------------------------------------
+#ifndef QC_swapH
+#define QC_swapH
+//---------------------------------------------------------------------------
+#include "QCalcUnit.h"
+//---------------------------------------------------------------------------
+
+class QC_swap : public QCalcUnit
+{
+private:
+    int TargetBit1;
+    int TargetBit2;
+
+public:
+    QC_swap(int t1,int t2);
+    static void calc(int t1, int t2, double R[], double I[], int N);
+    virtual void Calc(QBits *QBits);
+    virtual std::string GetName(void) const {
+        return "Swap";
+    }
+
+#ifdef __USE__MPI
+    static void calcmpi(int t1, int t2, double R[], double I[], int N);
+#endif
+
+};
+//---------------------------------------------------------------------------
+#endif
diff --git a/calcunits/QCalcManager.cpp b/calcunits/QCalcManager.cpp
new file mode 100644 (file)
index 0000000..45f439b
--- /dev/null
@@ -0,0 +1,96 @@
+//---------------------------------------------------------------------------\r
+// Management Class of QCalcUnit\r
+//---------------------------------------------------------------------------\r
+#include <iostream>\r
+#include <vector>\r
+\r
+#include "QCalcManager.h"\r
+#include "QCompilerCntl.h"\r
+#include "QCalcUnit.h"\r
+#include "QBits.h"\r
+//---------------------------------------------------------------------------\r
+/**\r
+ * Constructor\r
+ */\r
+QCalcManager::QCalcManager(void) {\r
+  mNumberOfQBits  = 0;\r
+  mQCalcUnits.clear();\r
+}\r
+//---------------------------------------------------------------------------\r
+/**\r
+ * Constructor\r
+ */\r
+QCalcManager::QCalcManager(std::istream &is){\r
+  mNumberOfQBits  = 0;\r
+  mQCalcUnits.clear();\r
+  AddFromIntermediate(is);\r
+}\r
+//---------------------------------------------------------------------------\r
+/**\r
+ * Destructor\r
+ */\r
+QCalcManager::~QCalcManager(){\r
+  DeleteAll();\r
+}\r
+//---------------------------------------------------------------------------\r
+// Interfaces\r
+//---------------------------------------------------------------------------\r
+/**\r
+ *  Compile intermediate\r
+ */\r
+bool\r
+QCalcManager::AddFromIntermediate(std::istream &is) {\r
+  QCompilerCntl qccntl(is);\r
+  QCalcUnit *cu;\r
+  DeleteAll();\r
+  if (true == qccntl.Compile()) {\r
+    unsigned int cntl_size = qccntl.GetNumberOfControl();\r
+    for (unsigned int i = 0; i < cntl_size; i++) {\r
+      cu = qccntl.AllocateControl(i);\r
+      if (NULL != cu) mQCalcUnits.push_back(cu);\r
+    }\r
+    mNumberOfQBits = qccntl.GetNumberOfQBits();\r
+    return true;\r
+  }else{\r
+    return false;\r
+  }\r
+}\r
+//---------------------------------------------------------------------------\r
+/**\r
+ *  Calculate\r
+ */\r
+void\r
+QCalcManager::Calc(QBits * const qBits) {\r
+  if (qBits->GetNumberOfQBits() >= mNumberOfQBits) {\r
+    int unit_count = mQCalcUnits.size();\r
+    for (int i = 0; i < unit_count; i++) {\r
+      mQCalcUnits[i]->Calc(qBits);\r
+    }\r
+  } else {\r
+    //TODO: Error\r
+  }\r
+}\r
+//---------------------------------------------------------------------------\r
+/**\r
+ *  AddUnit\r
+ */\r
+void\r
+QCalcManager::AddUnit(QCalcUnit *qc) {\r
+  if (qc) {\r
+    mQCalcUnits.push_back(qc);\r
+  }\r
+}\r
+//---------------------------------------------------------------------------\r
+/**\r
+ *  Delete units\r
+ */\r
+void\r
+QCalcManager::DeleteAll(void) {\r
+  mNumberOfQBits  = 0;\r
+  int vec_size = mQCalcUnits.size();\r
+  for (int i = 0; i < vec_size; i++) {\r
+    delete mQCalcUnits[i];\r
+  }\r
+  mQCalcUnits.clear();\r
+}\r
+//---------------------------------------------------------------------------\r
diff --git a/calcunits/QCalcManager.h b/calcunits/QCalcManager.h
new file mode 100644 (file)
index 0000000..54033ea
--- /dev/null
@@ -0,0 +1,47 @@
+//---------------------------------------------------------------------------\r
+// Management Class of QCalcUnit\r
+//---------------------------------------------------------------------------\r
+#ifndef QCalcManagerH\r
+#define QCalcManagerH\r
+//---------------------------------------------------------------------------\r
+#include <vector>\r
+#include <iostream>\r
+#include "QBits.h"\r
+#include "QCalcUnit.h"\r
+#include "QCompilerCntl.h"\r
+//---------------------------------------------------------------------------\r
+class QCalcManager\r
+{\r
+protected:\r
+    int     mNumberOfQBits;\r
+\r
+public:\r
+    QCalcManager(void);\r
+    QCalcManager(std::istream &is);\r
+    ~QCalcManager();\r
+\r
+//---------------------------------------------------------------------------\r
+// Interfaces\r
+//---------------------------------------------------------------------------\r
+    bool AddFromIntermediate(std::istream &is);\r
+    void Calc(QBits * const qBits);\r
+    void AddUnit(QCalcUnit *qc);\r
+    int  GetCalcUnitCount(void) const {\r
+        return mQCalcUnits.size();\r
+    }\r
+    QCalcUnit *CalcUnitAt(const int index) {\r
+        return mQCalcUnits[index];\r
+    }\r
+    void DeleteAll(void);\r
+    int GetNumberOfQBits(void) {\r
+        return mNumberOfQBits;\r
+    }\r
+    //void DeleteAt(const int index) {} //TODO:\r
+//---------------------------------------------------------------------------\r
+// Utility functions\r
+//---------------------------------------------------------------------------\r
+protected:\r
+    std::vector<QCalcUnit*> mQCalcUnits;\r
+};\r
+//---------------------------------------------------------------------------\r
+#endif\r
diff --git a/calcunits/QCalcUnit.cpp b/calcunits/QCalcUnit.cpp
new file mode 100644 (file)
index 0000000..3358d58
--- /dev/null
@@ -0,0 +1,174 @@
+//---------------------------------------------------------------------------
+//  Base Class of CalcUnit
+//---------------------------------------------------------------------------
+#include "QCalcUnit.h"
+//---------------------------------------------------------------------------
+#ifdef __USE__MPI
+int QCalcUnit::gMdata;
+int QCalcUnit::gNqubits;
+int QCalcUnit::gProcMask;
+int QCalcUnit::gProcBit;
+int QCalcUnit::gMyID;
+int QCalcUnit::gNumprocs;
+#endif
+
+//---------------------------------------------------------------------------
+/**
+ *
+**/
+unsigned int
+QCalcUnit::insert0(unsigned int i0, unsigned int BitNum) {
+    unsigned int msk = (1<<BitNum) -1;
+    return ((~msk & i0) << 1) | (msk & i0);
+}
+//---------------------------------------------------------------------------
+/**
+ *
+**/
+unsigned int
+QCalcUnit::insert1(unsigned int i0, unsigned int BitNum) {
+    unsigned int msk = (1<<BitNum) -1;
+    return ((~msk & i0) << 1) | (1 << BitNum) | (msk & i0);
+}
+
+//---------------------------------------------------------------------------
+// for MPI calculation
+//---------------------------------------------------------------------------
+#ifdef __USE__MPI
+//---------------------------------------------------------------------------
+/**
+ * N - number of qbits
+ */
+int
+QCalcUnit::initmpi(int N, int myid, int numprocs) {
+    // numproc must be a power of 2.
+    int p = -1;
+    int n = numprocs;
+    while (n){
+        n = n >> 1;
+        p++;
+    }
+    gProcBit = p;
+    gNqubits = N;
+    gMdata          = 1 << (N - gProcBit);
+    gNumprocs       = numprocs;
+    gProcMask       = (gNumprocs - 1) << (N-gProcBit);
+    gMyID           = myid;
+    return gMdata;
+}
+//---------------------------------------------------------------------------
+inline int
+QCalcUnit::getOriginalID(int id){
+    return  gMyID << ((gNqubits-gProcBit))|id;
+}
+//----------------------------------------------------------------------------
+inline int
+QCalcUnit::getProcFromID(int id){
+    return (id >> (gNqubits - gProcBit));
+}
+//----------------------------------------------------------------------------
+void
+QCalcUnit::initdata(double R[], double I[]) {
+    for (int i = 0; i < gMdata; i++) {
+        R[i] = 0;
+        I[i] = 0;
+    }
+    if (0 == gMyID) {
+        R[0] = 1;
+    }
+}
+//----------------------------------------------------------------------------
+/**
+ * Show Data
+ */
+void
+QCalcUnit::showdata(double R[], double I[]) {
+    for (int i = 0; i < gMdata; i++) {
+        printf("proc=%3d: idx = %03d:%f,%f\n",
+               gMyID, getOriginalID(i), R[i], I[i]);
+    }
+}
+//----------------------------------------------------------------------------
+/**
+ *  Common procedure to prepare data
+ *  Return Value:
+ *  true:   need to store data
+ *  false:  don't need to store
+ */
+bool
+QCalcUnit::setup(const double R[], const double I[],
+                 const unsigned int &ix0, const unsigned int &ix1,
+                 double &r0, double &i0,
+                 double &r1, double &i1) {
+    MPI_Status  status;
+    MPI_Request req;
+    const int   TAG = 0;
+
+    unsigned int idx0 = ix0 & ((1<<(gNqubits-gProcBit))-1);
+    unsigned int idx1 = ix1 & ((1<<(gNqubits-gProcBit))-1);
+
+    int p0 = getProcFromID(ix0);
+    int p1 = getProcFromID(ix1);
+
+    //----
+    // Communication with MPI
+    //----
+    if (p0 != gMyID && p1 != gMyID) {
+        return false;
+    }
+
+    if (p0 == gMyID && p1 == gMyID) {
+        r0 = R[idx0];
+        r1 = R[idx1];
+        i0 = I[idx0];
+        i1 = I[idx1];
+    }
+
+    if (p0 == gMyID && p1 != gMyID) {
+        r0 = R[idx0];
+        MPI_Isend(&r0, 1, MPI_DOUBLE, p1, TAG,MPI_COMM_WORLD,&req);
+        MPI_Irecv(&r1, 1, MPI_DOUBLE, p1, TAG, MPI_COMM_WORLD, &req);
+        MPI_Wait(&req, &status);
+
+        i0 = I[idx0];
+        MPI_Isend(&i0, 1, MPI_DOUBLE, p1, TAG, MPI_COMM_WORLD, &req);
+        MPI_Irecv(&i1, 1, MPI_DOUBLE, p1, TAG, MPI_COMM_WORLD, &req);
+        MPI_Wait(&req, &status);
+    }
+    if (p0 != gMyID && p1 == gMyID) {
+        r1 = R[idx1];
+        MPI_Isend(&r1, 1, MPI_DOUBLE, p0, TAG, MPI_COMM_WORLD, &req);
+        MPI_Irecv(&r0, 1, MPI_DOUBLE, p0, TAG, MPI_COMM_WORLD, &req);
+        MPI_Wait(&req, &status);
+
+        i1 = I[idx1];
+        MPI_Isend(&i1, 1, MPI_DOUBLE, p0, TAG, MPI_COMM_WORLD, &req);
+        MPI_Irecv(&i0, 1, MPI_DOUBLE, p0, TAG, MPI_COMM_WORLD, &req);
+        MPI_Wait(&req, &status);
+    }
+    return true;
+}
+//----------------------------------------------------------------------------
+/**
+ *  Common procedure to store data
+ */
+void QCalcUnit::store(double R[], double I[],
+                      const unsigned int &ix0, const unsigned int &ix1,
+                      const double &r0, const double &i0,
+                      const double &r1, const double &i1) {
+    int p0 = getProcFromID(ix0);
+    int p1 = getProcFromID(ix1);
+    unsigned int idx0 = ix0 & ((1<<(gNqubits-gProcBit))-1);
+    unsigned int idx1 = ix1 & ((1<<(gNqubits-gProcBit))-1);
+
+    if (p0 == gMyID) {
+        R[idx0] = r0;
+        I[idx0] = i0;
+    }
+    if (p1 == gMyID) {
+        R[idx1] = r1;
+        I[idx1] = i1;
+    }
+}
+//----------------------------------------------------------------------------
+#endif //__USE__MPI
diff --git a/calcunits/QCalcUnit.h b/calcunits/QCalcUnit.h
new file mode 100644 (file)
index 0000000..f1853cf
--- /dev/null
@@ -0,0 +1,69 @@
+//---------------------------------------------------------------------------
+//  Calc unit
+//---------------------------------------------------------------------------
+#ifndef QCalcUnitH
+#define QCalcUnitH
+//---------------------------------------------------------------------------
+#include <string>
+#include <sstream>
+
+#ifdef __USE__MPI
+#include <mpi.h>
+#endif //__USE__MPI
+
+#include "QBits.h"
+//---------------------------------------------------------------------------
+class QCalcUnit
+{
+protected :
+//---
+// for MPI
+//---
+#ifdef __USE__MPI
+    static int gMdata;  // the number of the states which each process treats
+    static int gNqubits;
+    static int gProcMask;
+    static int gProcBit;
+    static int gMyID;
+    static int gNumprocs;
+#endif //__USE__MPI
+
+
+public:
+    virtual void Calc(QBits *qBits) = 0;
+    virtual std::string GetName(void) const = 0;
+    static unsigned int insert0(unsigned int i0, unsigned int BitNum);
+    static unsigned int insert1(unsigned int i0, unsigned int BitNum);
+    static void swap(double &x,double &y) {
+        double tmp = x;
+        x = y;
+        y = tmp;
+    };
+    static void swap(int    &x,int    &y) {
+        int    tmp = x;
+        x = y;
+        y = tmp;
+    };
+
+//---
+// for MPI
+//---
+
+    static inline int getOriginalID(int id);
+    static inline int getProcFromID(int id);
+    static bool setup(const double R[], const double I[],
+                      const unsigned int &ix0, const unsigned int &ix1,
+                      double &r0, double &i0,
+                      double &r1, double &i1);
+    static void store(double R[], double I[],
+                      const unsigned int &ix0, const unsigned int &ix1,
+                      const double &r0, const double &i0,
+                      const double &r1, const double &i1);
+    static void showdata(double R[], double I[]);
+
+    static int initmpi(int N, int myid, int numprocs);
+    static void initdata(double R[], double I[]);
+
+};
+//---------------------------------------------------------------------------
+#endif //QCalcUnitH
diff --git a/calcunits/makefile b/calcunits/makefile
new file mode 100644 (file)
index 0000000..512b20b
--- /dev/null
@@ -0,0 +1,2 @@
+clean:
+       rm -f *.obj *.~* *.o
diff --git a/circuits/QBitbox.cpp b/circuits/QBitbox.cpp
new file mode 100644 (file)
index 0000000..876aa3a
--- /dev/null
@@ -0,0 +1,117 @@
+//---------------------------------------------------------------------------\r
+// Bit Information\r
+//---------------------------------------------------------------------------\r
+#include <stdlib.h>\r
+#include "QBitbox.h"\r
+//---------------------------------------------------------------------------\r
+QBitbox::QBitbox(int index) :QCircuit(0,index) {\r
+  Name = GetTypeStr();\r
+  Text = "|0>";\r
+  Index = index;\r
+  Enabled = true;\r
+  state = BIT_DOWN;\r
+}\r
+//---------------------------------------------------------------------------\r
+QBitbox::QBitbox(int x, int y, string Param) :QCircuit(0,y) {\r
+  Name = GetTypeStr();\r
+  Text = "|0>";\r
+  Index = y;\r
+  Enabled = true;\r
+  state = BIT_DOWN;\r
+  SetState(atoi(Param.c_str()));\r
+}\r
+//---------------------------------------------------------------------------\r
+void\r
+QBitbox::Draw(QDraw *qDraw) {\r
+  int GridSize = qDraw->GetGridSize();\r
+  int UnitSize = qDraw->GetUnitSize();\r
+  int d = (GridSize-UnitSize)/2;\r
+  int x1 = d;\r
+  int y1 = Index * GridSize+d;\r
+  int x2 = x1 + UnitSize;\r
+  int y2 = y1 + UnitSize;\r
+\r
+  qDraw->SetBrushColor(clWhite);\r
+  qDraw->FillRect(x1,y1,x2,y2);\r
+\r
+  if (!Enabled) {\r
+    qDraw->SetBrushColor(clRed);\r
+  } else {\r
+    qDraw->SetBrushColor(clBlack);\r
+  }\r
+\r
+  qDraw->FrameRect(x1,y1,x2,y2);\r
+\r
+  qDraw->SetBrushColor(clWhite);\r
+  ostringstream os;\r
+  os << "|" << state << ">";\r
+  qDraw->TextOut(x1+UnitSize/2,y1+UnitSize/2,os.str());\r
+}\r
+//---------------------------------------------------------------------------\r
+string\r
+QBitbox::GetCalcText(void) {\r
+  if (state == BIT_DOWN) {\r
+    return "blank";\r
+  }\r
+  ostringstream os;\r
+  os << "NOT(q[" << Y << "])";\r
+  return os.str();\r
+}\r
+//---------------------------------------------------------------------------\r
+void\r
+QBitbox::DrawPS(QPSDraw *psDraw) {\r
+\r
+  if (!Enabled)\r
+    return;\r
+  int GridSize = psDraw->GetGridSize();\r
+  int UnitSize = psDraw->GetUnitSize();\r
+  int d = (GridSize-UnitSize)/2;\r
+  int x1 = d;\r
+  int y1 = Index * GridSize+d;\r
+\r
+  psDraw->FillRect(GridSize*X,GridSize*Y,GridSize*X+GridSize,GridSize*Y+GridSize);\r
+  psDraw->TextOut(x1+UnitSize/2,y1+UnitSize/2,Text.c_str());\r
+}\r
+//---------------------------------------------------------------------------\r
+string\r
+QBitbox::GetParam(void) {\r
+  ostringstream os;\r
+  os << state;\r
+  return os.str();\r
+}\r
+//---------------------------------------------------------------------------\r
+void\r
+QBitbox::Reverse(int y) {\r
+  Index = y - Index;\r
+  Y = y - Y;\r
+}\r
+//---------------------------------------------------------------------------\r
+TRect\r
+QBitbox::GetOccupiedRect() {\r
+  return TRect(X, Y, X + 1, Y + 1);\r
+}\r
+//---------------------------------------------------------------------------\r
+void\r
+QBitbox::SetState(int st) {\r
+  state = st;\r
+  if (state == BIT_DOWN) {\r
+    Text = "|0>";\r
+  } else {\r
+    Text = "|1>";\r
+  }\r
+}\r
+//---------------------------------------------------------------------------\r
+int\r
+QBitbox::GetState() {\r
+  return state;\r
+}\r
+//---------------------------------------------------------------------------\r
+QCircuit*\r
+QBitbox::Clone() {\r
+  QBitbox *qb = new QBitbox(Index);\r
+  qb->SetState(GetState());\r
+  qb->Enabled = Enabled;\r
+  return (QCircuit*)qb;\r
+}\r
+//---------------------------------------------------------------------------\r
+\r
diff --git a/circuits/QBitbox.h b/circuits/QBitbox.h
new file mode 100644 (file)
index 0000000..2196490
--- /dev/null
@@ -0,0 +1,39 @@
+//---------------------------------------------------------------------------\r
+// Bit Information\r
+//---------------------------------------------------------------------------\r
+#ifndef QBitboxH\r
+#define QBitboxH\r
+#include "QCircuit.h"\r
+\r
+const int BIT_DOWN = 0;\r
+const int BIT_UP   = 1;\r
+//---------------------------------------------------------------------------\r
+class QBitbox : public QCircuit {\r
+private:\r
+  int Index;\r
+  int state;\r
+  string Text;\r
+\r
+public:\r
+  QBitbox(int index);\r
+  QBitbox(int x, int y, string Param);\r
+\r
+\r
+  bool Enabled;\r
+\r
+  virtual int        GetType(void)    { return QC_BITBOX; }\r
+  virtual string GetTypeStr(void) { return "QBitBox"; }\r
+\r
+  void Draw(QDraw *Draw);\r
+  string GetCalcText(void);\r
+  virtual void Calc(QBits *qBits) {}\r
+  void DrawPS(QPSDraw *psDraw);\r
+  string GetParam(void);\r
+  void Reverse(int y);\r
+  TRect GetOccupiedRect();\r
+  void SetState(int st);\r
+  int GetState();\r
+  QCircuit *Clone();\r
+};\r
+//---------------------------------------------------------------------------\r
+#endif\r
diff --git a/circuits/QCCnot.cpp b/circuits/QCCnot.cpp
new file mode 100644 (file)
index 0000000..5d3ab19
--- /dev/null
@@ -0,0 +1,156 @@
+//---------------------------------------------------------------------------\r
+// Toffoli Gate\r
+//---------------------------------------------------------------------------\r
+#include <stdlib.h>\r
+#include "QCCnot.h"\r
+#include "StrUtils.h"\r
+//---------------------------------------------------------------------------\r
+QCCNot::QCCNot(int x,int y) :QCircuit(x,y) {\r
+  Name = GetTypeStr();\r
+  Target1 = Y;\r
+  Target2 = Y;\r
+}\r
+//---------------------------------------------------------------------------\r
+QCCNot::QCCNot(int x,int y, string param) :QCircuit(x,y) {\r
+  Name = GetTypeStr();\r
+  Target1 = Y;\r
+  Target2 = Y;\r
+  vector<string> v = StrUtils::split_str(param);\r
+  Target1 = atoi(v[0].c_str());\r
+  Target2 = atoi(v[1].c_str());\r
+}\r
+//---------------------------------------------------------------------------\r
+void\r
+QCCNot::Draw(QDraw *qDraw) {\r
+\r
+  int GridSize = qDraw->GetGridSize();\r
+  int UnitSize = qDraw->GetUnitSize();\r
+\r
+  int tx = X;\r
+  int ty = Target1;\r
+\r
+  int tx1 = tx*GridSize + GridSize/2;\r
+  int ty1 = ty*GridSize + GridSize/2;\r
+  int tx2 = X*GridSize + GridSize/2;\r
+  int ty2 = Y*GridSize + GridSize/2;\r
+  qDraw->SetPenColor(clBlack);\r
+  qDraw->DrawLine(tx1,ty1,tx2,ty2);\r
+  qDraw->SetBrushColor(clBlack);\r
+  qDraw->Ellipse(tx1-4,ty1-4,tx1+5,ty1+5);\r
+\r
+  tx = X;\r
+  ty = Target2;\r
+\r
+  tx1 = tx*GridSize + GridSize/2;\r
+  ty1 = ty*GridSize + GridSize/2;\r
+  tx2 = X*GridSize + GridSize/2;\r
+  ty2 = Y*GridSize + GridSize/2;\r
+  qDraw->SetPenColor(clBlack);\r
+  qDraw->DrawLine(tx1,ty1,tx2,ty2);\r
+  qDraw->SetBrushColor(clBlack);\r
+  qDraw->Ellipse(tx1-4,ty1-4,tx1+5,ty1+5);\r
+\r
+  int d = (GridSize-UnitSize)/2;\r
+  int x1 = X * GridSize+d;\r
+  int y1 = Y * GridSize+d;\r
+  int x2 = x1 + UnitSize;\r
+  int y2 = y1 + UnitSize;\r
+\r
+  qDraw->SetBrushColor(clWhite);\r
+  qDraw->FillRect(x1,y1,x2,y2);\r
+  qDraw->SetPenColor(clBlack);\r
+  qDraw->SetBrushColor(clWhite);\r
+  qDraw->Ellipse(x1,y1,x2,y2);\r
+  qDraw->DrawLine(x1+UnitSize/2,y1,x1+UnitSize/2,y2);\r
+  qDraw->DrawLine(x1,y1+UnitSize/2,x2,y1+UnitSize/2);\r
+}\r
+//---------------------------------------------------------------------------\r
+string\r
+QCCNot::GetCalcText(void) {\r
+  ostringstream os;\r
+  os << "CCNOT(";\r
+  os << "q[" << Y       << "],";\r
+  os << "q[" << Target1 << "],";\r
+  os << "q[" << Target2 << "])";\r
+  return os.str();\r
+}\r
+//---------------------------------------------------------------------------\r
+void\r
+QCCNot::DrawPS(QPSDraw *psDraw) {\r
+\r
+  int GridSize = psDraw->GetGridSize();\r
+  int UnitSize = psDraw->GetUnitSize();\r
+\r
+  int tx = X;\r
+  int ty = Target1;\r
+\r
+  int tx1 = tx*GridSize + GridSize/2;\r
+  int ty1 = ty*GridSize + GridSize/2;\r
+  int tx2 = X*GridSize + GridSize/2;\r
+  int ty2 = Y*GridSize + GridSize/2;\r
+  psDraw->DrawLine(tx1,ty1,tx2,ty2);\r
+  psDraw->DrawFillCircle(tx1,ty1,4);\r
+\r
+  tx = X;\r
+  ty = Target2;\r
+\r
+  tx1 = tx*GridSize + GridSize/2;\r
+  ty1 = ty*GridSize + GridSize/2;\r
+  tx2 = X*GridSize + GridSize/2;\r
+  ty2 = Y*GridSize + GridSize/2;\r
+  psDraw->DrawLine(tx1,ty1,tx2,ty2);\r
+  psDraw->DrawFillCircle(tx1,ty1,4);\r
+\r
+  int d = (GridSize-UnitSize)/2;\r
+  int x1 = X * GridSize+d;\r
+  int y1 = Y * GridSize+d;\r
+  int x2 = x1 + UnitSize;\r
+  int y2 = y1 + UnitSize;\r
+\r
+  psDraw->FillRect(x1,y1,x2,y2);\r
+  psDraw->DrawCircle(X*GridSize + GridSize/2,Y*GridSize + GridSize/2,UnitSize/2);\r
+  psDraw->DrawLine(x1+UnitSize/2,y1,x1+UnitSize/2,y2);\r
+  psDraw->DrawLine(x1,y1+UnitSize/2,x2,y1+UnitSize/2);\r
+}\r
+//---------------------------------------------------------------------------\r
+string\r
+QCCNot::GetParam(void) {\r
+  ostringstream os;\r
+  os << Target1 << "," << Target2;\r
+  return os.str();\r
+}\r
+//---------------------------------------------------------------------------\r
+void\r
+QCCNot::Reverse(int y) {\r
+  Y = y - Y;\r
+  Target1 = y - Target1;\r
+  Target2 = y - Target2;\r
+}\r
+//---------------------------------------------------------------------------\r
+TRect QCCNot::GetOccupiedRect() {\r
+  TRect rc;\r
+  rc.left = this->X;\r
+  rc.right = this->X + 1;\r
+  rc.top = this->Y;\r
+  rc.bottom = this->Y + 1;\r
+  if (this->Target1 < this->Y) {\r
+    rc.top = this->Target1;\r
+  } else {\r
+    rc.bottom = this->Target1 + 1;\r
+  }\r
+\r
+  if (this->Target2 < rc.top) {\r
+    rc.top = this->Target2;\r
+  } else if (this->Target2 >= rc.bottom) {\r
+    rc.bottom = this->Target2 + 1;\r
+  }\r
+  return rc;\r
+}\r
+//--------------------------------------------------------------------------\r
+QCircuit *QCCNot::Clone() {\r
+  QCCNot * qc = new QCCNot(X, Y);\r
+  qc->SetTarget1(GetTarget1());\r
+  qc->SetTarget2(GetTarget2());\r
+  return (QCircuit*)qc;\r
+}\r
+//---------------------------------------------------------------------------\r
diff --git a/circuits/QCCnot.h b/circuits/QCCnot.h
new file mode 100644 (file)
index 0000000..c306ecf
--- /dev/null
@@ -0,0 +1,37 @@
+//---------------------------------------------------------------------------\r
+#ifndef QCCnotH\r
+#define QCCnotH\r
+//---------------------------------------------------------------------------\r
+#include "QCircuit.h"\r
+//---------------------------------------------------------------------------\r
+class QCCNot : public QCircuit {\r
+private:\r
+\r
+  int Target1;\r
+  int Target2;\r
+\r
+public:\r
+  QCCNot(int x,int y);\r
+  QCCNot(int x,int y, string Param);\r
+\r
+  virtual int        GetType(void)    { return QC_CCNOT; }\r
+  virtual string GetTypeStr(void) { return "QCCNot"; }\r
+\r
+  string GetCalcText(void);\r
+\r
+  void SetTarget1(int t) {Target1=t;};\r
+  void SetTarget2(int t) {Target2=t;};\r
+  int GetTarget1(void) {return Target1;};\r
+  int GetTarget2(void) {return Target2;};\r
+\r
+\r
+  void Draw(QDraw *Draw);\r
+  void DrawPS(QPSDraw *psDraw);\r
+  string GetParam(void);\r
+  void Reverse(int y);\r
+  TRect GetOccupiedRect();\r
+  QCircuit *Clone();\r
+\r
+};\r
+//---------------------------------------------------------------------------\r
+#endif\r
diff --git a/circuits/QCRot.cpp b/circuits/QCRot.cpp
new file mode 100644 (file)
index 0000000..5033a6c
--- /dev/null
@@ -0,0 +1,135 @@
+//---------------------------------------------------------------------------\r
+#include "QCRot.h"\r
+#include "StrUtils.h"\r
+//---------------------------------------------------------------------------\r
+QCRot::QCRot(int x,int y) :QCircuit(x,y) {\r
+  Name = GetTypeStr();\r
+  Target = Y;\r
+  Phase = 0;\r
+}\r
+//---------------------------------------------------------------------------\r
+QCRot::QCRot(int x,int y, string param) :QCircuit(x,y) {\r
+  Name = GetTypeStr();\r
+  Target = Y;\r
+  Phase = 0;\r
+  vector<string> v = StrUtils::split_str(param);\r
+  Target = atoi(v[0].c_str());\r
+  Phase = atof(v[1].c_str());\r
+}\r
+//---------------------------------------------------------------------------\r
+void\r
+QCRot::Draw(QDraw *qDraw) {\r
+  int GridSize = qDraw->GetGridSize();\r
+  int UnitSize = qDraw->GetUnitSize();\r
+\r
+\r
+  int tx = X;\r
+  int ty = Target;\r
+\r
+  int tx1 = tx*GridSize + GridSize/2;\r
+  int ty1 = ty*GridSize + GridSize/2;\r
+  int tx2 = X*GridSize + GridSize/2;\r
+  int ty2 = Y*GridSize + GridSize/2;\r
+  qDraw->SetPenColor(clBlack);\r
+  qDraw->DrawLine(tx1,ty1,tx2,ty2);\r
+  qDraw->SetBrushColor(clBlack);\r
+\r
+  qDraw->Ellipse(tx1-4,ty1-4,tx1+5,ty1+5);\r
+\r
+\r
+  int d = (GridSize-UnitSize)/2;\r
+  int x1 = X * GridSize+d;\r
+  int y1 = Y * GridSize+d;\r
+  int x2 = x1 + UnitSize;\r
+  int y2 = y1 + UnitSize;\r
+\r
+  qDraw->SetBrushColor(clWhite);\r
+  qDraw->FillRect(x1,y1,x2,y2);\r
+  qDraw->SetBrushColor(clPurple);\r
+  qDraw->FrameRect(x1,y1,x2,y2);\r
+  qDraw->SetPenColor(clBlack);\r
+  qDraw->SetBrushColor(clWhite);\r
+  ostringstream os;\r
+  os << Phase;\r
+  qDraw->TextOut(x1+UnitSize/2,y1+UnitSize/2, os.str());\r
+}\r
+//---------------------------------------------------------------------------\r
+void\r
+QCRot::Reverse(int y) {\r
+  Y = y-Y;\r
+  Target = y - Target;\r
+}\r
+//---------------------------------------------------------------------------\r
+string\r
+QCRot::GetCalcText(void) {\r
+  ostringstream os;\r
+  os << "CROT(";\r
+  os << "q[" << Y << "],";\r
+  os << "q[" << Target << "],";\r
+  os << Phase << ")";\r
+  return os.str();\r
+}\r
+\r
+//---------------------------------------------------------------------------\r
+void\r
+QCRot::DrawPS(QPSDraw *psDraw) {\r
+  int GridSize = psDraw->GetGridSize();\r
+  int UnitSize = psDraw->GetUnitSize();\r
+\r
+  int tx = X;\r
+  int ty = Target;\r
+\r
+  int tx1 = tx*GridSize + GridSize/2;\r
+  int ty1 = ty*GridSize + GridSize/2;\r
+  int tx2 = X*GridSize + GridSize/2;\r
+  int ty2 = Y*GridSize + GridSize/2;\r
+  psDraw->DrawLine(tx1,ty1,tx2,ty2);\r
+  psDraw->DrawFillCircle(tx1,ty1,4);\r
+\r
+  int d = (GridSize-UnitSize)/2;\r
+  int x1 = X * GridSize+d;\r
+  int y1 = Y * GridSize+d;\r
+  int x2 = x1 + UnitSize;\r
+  int y2 = y1 + UnitSize;\r
+\r
+  psDraw->FillRect(x1,y1,x2,y2);\r
+\r
+\r
+  psDraw->FillRect(x1,y1,x2,y2);\r
+  psDraw->FrameRect(x1,y1,x2,y2);\r
+  ostringstream os;\r
+  os << Phase;\r
+  psDraw->TextOut(x1+UnitSize/2,y1+UnitSize/2,os.str());\r
+}\r
+//---------------------------------------------------------------------------\r
+string\r
+QCRot::GetParam(void) {\r
+  ostringstream os;\r
+  os << Target << "," << Phase;\r
+  return os.str();\r
+}\r
+//---------------------------------------------------------------------------\r
+TRect\r
+QCRot::GetOccupiedRect() {\r
+  TRect rc;\r
+  rc.left = X;\r
+  rc.right = X + 1;\r
+  rc.top = Y;\r
+  rc.bottom = Y + 1;\r
+  if (Target < Y) {\r
+    rc.top = Target;\r
+  } else {\r
+    rc.bottom = Target + 1;\r
+  }\r
+  return rc;\r
+}\r
+//--------------------------------------------------------------------------\r
+QCircuit *\r
+QCRot::Clone() {\r
+  QCRot * qc = new QCRot(X, Y);\r
+  qc->SetTarget(GetTarget());\r
+  qc->SetPhase(GetPhase());\r
+  return (QCircuit*)qc;\r
+}\r
+//---------------------------------------------------------------------------\r
+\r
diff --git a/circuits/QCRot.h b/circuits/QCRot.h
new file mode 100644 (file)
index 0000000..9911efc
--- /dev/null
@@ -0,0 +1,39 @@
+//---------------------------------------------------------------------------\r
+#ifndef QCRotH\r
+#define QCRotH\r
+//---------------------------------------------------------------------------\r
+#include "QCircuit.h"\r
+//---------------------------------------------------------------------------\r
+class QCRot : public QCircuit {\r
+private:\r
+\r
+  int Target;\r
+  double Phase;\r
+\r
+public:\r
+  QCRot(int x,int y);\r
+  QCRot(int x,int y, string Param);\r
+\r
+  virtual int        GetType(void)    { return QC_CROT; }\r
+  virtual string GetTypeStr(void) { return "QCRot"; }\r
+\r
+  string GetCalcText(void);\r
+\r
+  void SetTarget(int t) {Target=t;};\r
+  int GetTarget(void) {return Target;};\r
+\r
+  void Draw(QDraw *Draw);\r
+  void DrawPS(QPSDraw *psDraw);\r
+  string GetParam(void);\r
+  void Reverse(int y);\r
+  TRect GetOccupiedRect();\r
+  QCircuit *Clone();\r
+\r
+  double GetPhase(void){\r
+    return Phase;\r
+  };\r
+  void SetPhase(double p){\r
+    Phase = p;\r
+  };\r
+};\r
+#endif\r
diff --git a/circuits/QCircuit.cpp b/circuits/QCircuit.cpp
new file mode 100644 (file)
index 0000000..fd1dade
--- /dev/null
@@ -0,0 +1,138 @@
+//---------------------------------------------------------------------------\r
+// Class for Circuits\r
+//---------------------------------------------------------------------------\r
+#include "QCircuit.h"\r
+#include "QCircuitAll.h"\r
+\r
+//---------------------------------------------------------------------------\r
+QCircuit::QCircuit(int x,int y) {\r
+  X = x;\r
+  Y = y;\r
+}\r
+//---------------------------------------------------------------------------\r
+int\r
+QCircuit::GetType(string Type) {\r
+\r
+  if (Type =="QBitBox") {\r
+    return QC_BITBOX;\r
+  } else if (Type =="QWalsh") {\r
+    return QC_WALSH;\r
+  } else if (Type == "QCNot") {\r
+    return QC_CNOT;\r
+  } else if (Type == "QCCNot") {\r
+    return QC_CCNOT;\r
+  } else if (Type == "QMeasure") {\r
+    return QC_MEASURE;\r
+  } else if (Type == "QTextBox") {\r
+    return QC_TEXTBOX;\r
+  } else if (Type == "QPauliX") {\r
+    return QC_PAULIX;\r
+  } else if (Type == "QPauliY") {\r
+    return QC_PAULIY;\r
+  } else if (Type == "QPauliZ") {\r
+    return QC_PAULIZ;\r
+  } else if (Type == "QSwap") {\r
+    return QC_SWAP;\r
+  } else if (Type == "QCRot") {\r
+    return QC_CROT;\r
+  } else if (Type == "QNOT") {\r
+    return QC_NOT;\r
+  } else if (Type == "QRot") {\r
+    return QC_ROT;\r
+  }\r
+  return -1;\r
+}\r
+//---------------------------------------------------------------------------\r
+const char*\r
+QCircuit::GetTypeStr(int Type) {\r
+  switch (Type) {\r
+  case QC_BITBOX:\r
+    return "QBitbox";\r
+\r
+  case QC_WALSH:\r
+    return "QWalsh";\r
+\r
+  case QC_CNOT:\r
+    return "QCNot";\r
+\r
+  case QC_CCNOT:\r
+    return "QCCNot";\r
+\r
+  case QC_MEASURE:\r
+    return "QMesure";\r
+\r
+  case QC_TEXTBOX:\r
+    return "QTextBox";\r
+\r
+  case QC_PAULIX:\r
+    return "QPauliX";\r
+\r
+  case QC_PAULIY:\r
+    return "QPauliY";\r
+\r
+  case QC_PAULIZ:\r
+    return "QPauliZ";\r
+\r
+  case QC_SWAP:\r
+    return "QSwap";\r
+\r
+  case QC_CROT:\r
+    return "QCRot";\r
+  }\r
+  return "";\r
+}\r
+//---------------------------------------------------------------------------\r
+QCircuit*\r
+QCircuit::Create(string TypeStr, int x, int y, string Param) {\r
+\r
+  QCircuit *qc;\r
+  int Type = GetType(TypeStr);\r
+  switch (Type) {\r
+\r
+  case QC_BITBOX:\r
+    return new QBitbox(x,y,Param);\r
+\r
+  case QC_WALSH:\r
+    return new QWalsh(x,y);\r
+\r
+  case QC_MEASURE:\r
+    return new QMeasure(x,y);\r
+\r
+  case QC_PAULIX:\r
+    return new QPauliX(x,y);\r
+\r
+  case QC_PAULIY:\r
+    return new QPauliY(x,y);\r
+\r
+  case QC_PAULIZ:\r
+    return new QPauliZ(x,y);\r
+\r
+  case QC_ROT:\r
+    return new QRot(x,y,Param);\r
+\r
+  case QC_NOT:\r
+    return new QNot(x, y);\r
+\r
+  case QC_CNOT:\r
+    return new QCNot(x,y,Param);\r
+\r
+  case QC_CCNOT:\r
+    return new QCCNot(x,y,Param);\r
+\r
+  case QC_SWAP:\r
+    return new QSwap(x,y, Param);\r
+\r
+  case QC_CROT:\r
+    return new QCRot(x,y, Param);\r
+  }\r
+  return NULL;\r
+}\r
+//---------------------------------------------------------------------------\r
+string\r
+QCircuit::GetSaveText(void) {\r
+  ostringstream os;\r
+  os << X << "," << Y << "," << Name << ",\""<< GetParam() << "\"";\r
+  return os.str();\r
+}\r
+//---------------------------------------------------------------------------\r
+\r
diff --git a/circuits/QCircuit.h b/circuits/QCircuit.h
new file mode 100644 (file)
index 0000000..d54bf2e
--- /dev/null
@@ -0,0 +1,73 @@
+//---------------------------------------------------------------------------\r
+// Class for Circuits\r
+//---------------------------------------------------------------------------\r
+#ifndef QCircuitH\r
+#define QCircuitH\r
+\r
+//---------------------------------------------------------------------------\r
+#include <vector>\r
+#include <map>\r
+#include <string>\r
+#include "QBits.h"\r
+#include "QDraw.h"\r
+#include "QPSDraw.h"\r
+//---------------------------------------------------------------------------\r
+\r
+enum QC_TYPES{\r
+  QC_NULL = -1, // No circuit\r
+  QC_BITBOX  = 0,\r
+  QC_WALSH   = 1,\r
+  QC_CNOT    = 2,\r
+  QC_CCNOT   = 3,\r
+  QC_TEXTBOX = 4,\r
+  QC_MEASURE = 5,\r
+  QC_PAULIX  = 6,\r
+  QC_PAULIY  = 7,\r
+  QC_PAULIZ  = 8,\r
+  QC_SWAP    = 9,\r
+  QC_CROT    = 10,\r
+  QC_NOT     = 11,\r
+  QC_ROT     = 12\r
+};\r
+\r
+\r
+class QCircuit {\r
+\r
+\r
+private:\r
+\r
+protected:\r
+  int X,Y;\r
+  string Name;\r
+\r
+public:\r
+\r
+  QCircuit(int x, int y);\r
+  static QCircuit* Create(string TypeStr, int x, int y, string Param);\r
+\r
+  int  GetX(void)  { return X; }\r
+  int  GetY(void)  { return Y; }\r
+  void SetX(int x) { X = x;    }\r
+  void SetY(int y) { Y = y;    }\r
+\r
+  static int        GetType(string Type);\r
+  static const char* GetTypeStr(int Type);\r
+\r
+  virtual int        GetType(void) { return QC_NULL; }\r
+  virtual string GetTypeStr(void) { return ""; }\r
+\r
+  virtual void Draw(QDraw *qDraw) {}\r
+  virtual string GetCalcText(void) {return "";}\r
+  virtual void DrawPS(QPSDraw *psDraw) {}\r
+  virtual string GetSaveText(void);\r
+  virtual string GetParam(void) {return "";}\r
+  virtual void ShowParamForm(void) {}\r
+  virtual void Reverse(int y) {}\r
+  virtual TRect GetOccupiedRect() {TRect rc; return rc;}\r
+  virtual QCircuit *Clone() {QCircuit *qc = new QCircuit(X,Y); return qc;}\r
+};\r
+\r
+typedef vector<QCircuit *> QList;\r
+\r
+//---------------------------------------------------------------------------\r
+#endif //QCircuitH\r
diff --git a/circuits/QCircuitAll.h b/circuits/QCircuitAll.h
new file mode 100644 (file)
index 0000000..0850d37
--- /dev/null
@@ -0,0 +1,12 @@
+#include "QBitbox.h"
+#include "QCCnot.h"
+#include "QCRot.h"
+#include "QCnot.h"
+#include "QMeasure.h"
+#include "QNot.h"
+#include "QPauliX.h"
+#include "QPauliY.h"
+#include "QPauliZ.h"
+#include "QRot.h"
+#include "QSwap.h"
+#include "QWalsh.h"
diff --git a/circuits/QCnot.cpp b/circuits/QCnot.cpp
new file mode 100644 (file)
index 0000000..11a057c
--- /dev/null
@@ -0,0 +1,122 @@
+//---------------------------------------------------------------------------\r
+// Controled Not\r
+//---------------------------------------------------------------------------\r
+#include <sstream>\r
+#include <stdlib.h>\r
+#include "QCnot.h"\r
+//---------------------------------------------------------------------------\r
+QCNot::QCNot(int x,int y) :QCircuit(x,y) {\r
+  Name = GetTypeStr();\r
+  Target = Y;\r
+}\r
+//---------------------------------------------------------------------------\r
+QCNot::QCNot(int x,int y, string Param) :QCircuit(x,y) {\r
+  Name = GetTypeStr();\r
+  Target = atoi(Param.c_str());\r
+}\r
+//---------------------------------------------------------------------------\r
+void\r
+QCNot::Draw(QDraw *qDraw) {\r
+  int GridSize = qDraw->GetGridSize();\r
+  int UnitSize = qDraw->GetUnitSize();\r
+\r
+  int tx = X;\r
+  int ty = Target;\r
+\r
+  int tx1 = tx*GridSize + GridSize/2;\r
+  int ty1 = ty*GridSize + GridSize/2;\r
+  int tx2 = X*GridSize + GridSize/2;\r
+  int ty2 = Y*GridSize + GridSize/2;\r
+  qDraw->SetPenColor(clBlack);\r
+  qDraw->DrawLine(tx1,ty1,tx2,ty2);\r
+  qDraw->SetBrushColor(clBlack);\r
+\r
+  qDraw->Ellipse(tx1-4,ty1-4,tx1+5,ty1+5);\r
+\r
+\r
+  int d = (GridSize-UnitSize)/2;\r
+  int x1 = X * GridSize+d;\r
+  int y1 = Y * GridSize+d;\r
+  int x2 = x1 + UnitSize;\r
+  int y2 = y1 + UnitSize;\r
+\r
+  qDraw->SetBrushColor(clWhite);\r
+  qDraw->FillRect(x1,y1,x2,y2);\r
+  qDraw->SetPenColor(clBlack);\r
+  qDraw->SetBrushColor(clWhite);\r
+  qDraw->Ellipse(x1,y1,x2,y2);\r
+  qDraw->DrawLine(x1+UnitSize/2,y1,x1+UnitSize/2,y2);\r
+  qDraw->DrawLine(x1,y1+UnitSize/2,x2,y1+UnitSize/2);\r
+}\r
+//---------------------------------------------------------------------------\r
+void QCNot::Reverse(int y) {\r
+  Y = y-Y;\r
+  Target = y - Target;\r
+}\r
+//---------------------------------------------------------------------------\r
+string\r
+QCNot::GetCalcText(void) {\r
+  ostringstream os;\r
+  os << "CNOT(";\r
+  os << "q[" << Y << "],";\r
+  os << "q[" << Target << "])";\r
+  return os.str();\r
+}\r
+//---------------------------------------------------------------------------\r
+void\r
+QCNot::DrawPS(QPSDraw *psDraw) {\r
+  int GridSize = psDraw->GetGridSize();\r
+  int UnitSize = psDraw->GetUnitSize();\r
+\r
+  int tx = X;\r
+  int ty = Target;\r
+\r
+  int tx1 = tx*GridSize + GridSize/2;\r
+  int ty1 = ty*GridSize + GridSize/2;\r
+  int tx2 = X*GridSize + GridSize/2;\r
+  int ty2 = Y*GridSize + GridSize/2;\r
+  psDraw->DrawLine(tx1,ty1,tx2,ty2);\r
+  psDraw->DrawFillCircle(tx1,ty1,4);\r
+\r
+  int d = (GridSize-UnitSize)/2;\r
+  int x1 = X * GridSize+d;\r
+  int y1 = Y * GridSize+d;\r
+  int x2 = x1 + UnitSize;\r
+  int y2 = y1 + UnitSize;\r
+\r
+  psDraw->FillRect(x1,y1,x2,y2);\r
+\r
+  psDraw->DrawCircle(X*GridSize + GridSize/2,Y*GridSize + GridSize/2,UnitSize/2);\r
+  psDraw->DrawLine(x1+UnitSize/2,y1,x1+UnitSize/2,y2);\r
+  psDraw->DrawLine(x1,y1+UnitSize/2,x2,y1+UnitSize/2);\r
+}\r
+//---------------------------------------------------------------------------\r
+string\r
+QCNot::GetParam(void) {\r
+  ostringstream os;\r
+  os << Target;\r
+  return os.str();\r
+}\r
+//---------------------------------------------------------------------------\r
+TRect\r
+QCNot::GetOccupiedRect() {\r
+  TRect rc;\r
+  rc.left = X;\r
+  rc.right = X + 1;\r
+  rc.top = Y;\r
+  rc.bottom = Y + 1;\r
+  if (Target < Y) {\r
+    rc.top = Target;\r
+  } else {\r
+    rc.bottom = Target + 1;\r
+  }\r
+  return rc;\r
+}\r
+//---------------------------------------------------------------------------\r
+QCircuit *\r
+QCNot::Clone() {\r
+  QCNot * qc = new QCNot(X, Y);\r
+  qc->SetTarget(GetTarget());\r
+  return (QCircuit*)qc;\r
+}\r
+//---------------------------------------------------------------------------\r
diff --git a/circuits/QCnot.h b/circuits/QCnot.h
new file mode 100644 (file)
index 0000000..4cd2114
--- /dev/null
@@ -0,0 +1,34 @@
+//---------------------------------------------------------------------------\r
+#ifndef QCnotH\r
+#define QCnotH\r
+//---------------------------------------------------------------------------\r
+#include "QCircuit.h"\r
+//---------------------------------------------------------------------------\r
+class QCNot : public QCircuit {\r
+private:\r
+\r
+  int Target;\r
+\r
+public:\r
+  QCNot(int x,int y);\r
+  QCNot(int x,int y, string Param);\r
+\r
+\r
+  virtual int        GetType(void)    { return QC_CNOT; }\r
+  virtual string GetTypeStr(void) { return "QCNot"; }\r
+\r
+  string GetCalcText(void);\r
+\r
+  void SetTarget(int t) {Target=t;};\r
+  int GetTarget(void) {return Target;};\r
+\r
+  void Draw(QDraw *Draw);\r
+  void DrawPS(QPSDraw *psDraw);\r
+  void Reverse(int y);\r
+  TRect GetOccupiedRect();\r
+  QCircuit *Clone();\r
+  string GetParam(void);\r
+\r
+};\r
+//---------------------------------------------------------------------------\r
+#endif\r
diff --git a/circuits/QMeasure.cpp b/circuits/QMeasure.cpp
new file mode 100644 (file)
index 0000000..cc538d9
--- /dev/null
@@ -0,0 +1,44 @@
+//---------------------------------------------------------------------------\r
+#include <sstream>\r
+#include "QMeasure.h"\r
+//---------------------------------------------------------------------------\r
+QMeasure::QMeasure(int x,int y) :QCircuit(x,y) {\r
+  Name = GetTypeStr();\r
+}\r
+//---------------------------------------------------------------------------\r
+void\r
+QMeasure::Draw(QDraw *qDraw) {\r
+  qDraw->DrawMeasure(X,Y);\r
+}\r
+//---------------------------------------------------------------------------\r
+void QMeasure::DrawPS(QPSDraw *psDraw) {\r
+  int GridSize = psDraw->GetGridSize();\r
+  int UnitSize = psDraw->GetUnitSize();\r
+  int d = (GridSize-UnitSize)/2;\r
+  int x1 = X * GridSize+d;\r
+  int y1 = Y * GridSize+d;\r
+  int x2 = x1 + UnitSize;\r
+  int y2 = y1 + UnitSize;\r
+\r
+  psDraw->FillRect(x1,y1,x2+d*2,y2);\r
+  psDraw->FrameRect(x1,y1,x2,y2);\r
+  psDraw->DrawMeasure(X*GridSize + UnitSize/2+d,Y*GridSize+d+UnitSize/4);\r
+}\r
+//---------------------------------------------------------------------------\r
+void QMeasure::Reverse(int y) {\r
+  Y = y-Y;\r
+}\r
+//---------------------------------------------------------------------------\r
+string\r
+QMeasure::GetCalcText(void) {\r
+  ostringstream os;\r
+  os << "MEASURE(q[" << Y << "])";\r
+  return os.str();\r
+}\r
+//---------------------------------------------------------------------------\r
+TRect\r
+QMeasure::GetOccupiedRect() {\r
+  return TRect(X, Y, X + 1, Y + 1);\r
+}\r
+//---------------------------------------------------------------------------\r
+\r
diff --git a/circuits/QMeasure.h b/circuits/QMeasure.h
new file mode 100644 (file)
index 0000000..e902555
--- /dev/null
@@ -0,0 +1,21 @@
+//---------------------------------------------------------------------------\r
+#ifndef QMeasureH\r
+#define QMeasureH\r
+//---------------------------------------------------------------------------\r
+#include "QCircuit.h"\r
+\r
+class QMeasure : public QCircuit {\r
+private:\r
+\r
+public:\r
+  QMeasure(int x,int y);\r
+  virtual int        GetType(void)    { return QC_MEASURE; }\r
+  virtual string GetTypeStr(void) { return "QMeasure"; }\r
+  string GetCalcText(void);\r
+  void Draw(QDraw *Draw);\r
+  void DrawPS(QPSDraw *psDraw);\r
+  void Reverse(int y);\r
+  TRect GetOccupiedRect();\r
+};\r
+//---------------------------------------------------------------------------\r
+#endif\r
diff --git a/circuits/QNot.cpp b/circuits/QNot.cpp
new file mode 100644 (file)
index 0000000..4e6bc2d
--- /dev/null
@@ -0,0 +1,69 @@
+//---------------------------------------------------------------------------\r
+#include "QNot.h"\r
+//---------------------------------------------------------------------------\r
+QNot::QNot(int x,int y) :QCircuit(x,y) {\r
+  Name = GetTypeStr();\r
+}\r
+//---------------------------------------------------------------------------\r
+void\r
+QNot::Draw(QDraw *qDraw) {\r
+\r
+  int GridSize = qDraw->GetGridSize();\r
+  int UnitSize = qDraw->GetUnitSize();\r
+  int d = (GridSize-UnitSize)/2;\r
+  int x1 = X * GridSize+d;\r
+  int y1 = Y * GridSize+d;\r
+  int x2 = x1 + UnitSize;\r
+  int y2 = y1 + UnitSize;\r
+\r
+  qDraw->SetBrushColor(clWhite);\r
+  qDraw->FillRect(x1,y1,x2,y2);\r
+  qDraw->SetPenColor(clBlack);\r
+  qDraw->SetBrushColor(clWhite);\r
+  qDraw->Ellipse(x1,y1,x2,y2);\r
+  qDraw->DrawLine(x1+UnitSize/2,y1,x1+UnitSize/2,y2);\r
+  qDraw->DrawLine(x1,y1+UnitSize/2,x2,y1+UnitSize/2);\r
+}\r
+//---------------------------------------------------------------------------\r
+string\r
+QNot::GetCalcText(void) {\r
+  ostringstream os;\r
+  os << "NOT(q[" << Y << "])";\r
+  return os.str();\r
+}\r
+//---------------------------------------------------------------------------\r
+void\r
+QNot::DrawPS(QPSDraw *psDraw) {\r
+  int GridSize = psDraw->GetGridSize();\r
+  int UnitSize = psDraw->GetUnitSize();\r
+  int d = (GridSize-UnitSize)/2;\r
+  int x1 = X * GridSize+d;\r
+  int y1 = Y * GridSize+d;\r
+  int x2 = x1 + UnitSize;\r
+  int y2 = y1 + UnitSize;\r
+\r
+  psDraw->FillRect(x1,y1,x2,y2);\r
+  psDraw->DrawCircle(X*GridSize + GridSize/2,Y*GridSize + GridSize/2,UnitSize/2);\r
+  psDraw->DrawLine(x1+UnitSize/2,y1,x1+UnitSize/2,y2);\r
+  psDraw->DrawLine(x1,y1+UnitSize/2,x2,y1+UnitSize/2);\r
+}\r
+//---------------------------------------------------------------------------\r
+void\r
+QNot::Reverse(int y) {\r
+  Y = y - Y;\r
+}\r
+//---------------------------------------------------------------------------\r
+TRect\r
+QNot::GetOccupiedRect() {\r
+  return TRect(X, Y, X + 1, Y + 1);\r
+}\r
+//---------------------------------------------------------------------------\r
+/**\r
+* Construct clone object\r
+**/\r
+QCircuit *\r
+QNot::Clone() {\r
+  QNot *qn = new QNot(X, Y);\r
+  return (QCircuit*)qn;\r
+}\r
+//---------------------------------------------------------------------------\r
diff --git a/circuits/QNot.h b/circuits/QNot.h
new file mode 100644 (file)
index 0000000..37b2753
--- /dev/null
@@ -0,0 +1,25 @@
+//---------------------------------------------------------------------------\r
+#ifndef QNotH\r
+#define QNotH\r
+\r
+#include "QCircuit.h"\r
+//---------------------------------------------------------------------------\r
+class QNot : public QCircuit {\r
+private:\r
+\r
+public:\r
+  QNot(int x,int y);\r
+\r
+\r
+  virtual int        GetType(void)    { return QC_NOT; }\r
+  virtual string GetTypeStr(void) { return "QNOT"; }\r
+\r
+  void Draw(QDraw *Draw);\r
+  string GetCalcText(void);\r
+  void DrawPS(QPSDraw *psDraw);\r
+  void Reverse(int y);\r
+  TRect GetOccupiedRect();\r
+  QCircuit *Clone();\r
+};\r
+//---------------------------------------------------------------------------\r
+#endif\r
diff --git a/circuits/QPauliX.cpp b/circuits/QPauliX.cpp
new file mode 100644 (file)
index 0000000..1fd11b9
--- /dev/null
@@ -0,0 +1,68 @@
+//---------------------------------------------------------------------------\r
+#include "QPauliX.h"\r
+//---------------------------------------------------------------------------\r
+QPauliX::QPauliX(int x, int y) : QCircuit(x,y) {\r
+  Name = GetTypeStr();\r
+}\r
+//---------------------------------------------------------------------------\r
+void\r
+QPauliX::Draw(QDraw* qDraw) {\r
+\r
+  int GridSize = qDraw->GetGridSize();\r
+  int UnitSize = qDraw->GetUnitSize();\r
+  int d = (GridSize-UnitSize)/2;\r
+  int x1 = X * GridSize+d;\r
+  int y1 = Y * GridSize+d;\r
+  int x2 = x1 + UnitSize;\r
+  int y2 = y1 + UnitSize;\r
+\r
+  qDraw->SetBrushColor(clWhite);\r
+  qDraw->FillRect(x1,y1,x2,y2);\r
+  qDraw->SetBrushColor(clLime);\r
+  qDraw->FrameRect(x1,y1,x2,y2);\r
+\r
+  qDraw->SetBrushColor(clWhite);\r
+  qDraw->TextOut(x1+UnitSize/2,y1+UnitSize/2,"X");\r
+\r
+}\r
+//---------------------------------------------------------------------------\r
+void QPauliX::DrawPS(QPSDraw * psDraw) {\r
+  int GridSize = psDraw->GetGridSize();\r
+  int UnitSize = psDraw->GetUnitSize();\r
+  int d = (GridSize-UnitSize)/2;\r
+  int x1 = X * GridSize+d;\r
+  int y1 = Y * GridSize+d;\r
+  int x2 = x1 + UnitSize;\r
+  int y2 = y1 + UnitSize;\r
+\r
+  psDraw->FillRect(x1,y1,x2,y2);\r
+  psDraw->FrameRect(x1,y1,x2,y2);\r
+\r
+  psDraw->TextOut(x1+UnitSize/2,y1+UnitSize/2,"X");\r
+}\r
+//---------------------------------------------------------------------------\r
+string\r
+QPauliX::GetCalcText(void) {\r
+  ostringstream os;\r
+  os << "PAULIX(q[" << Y << "])";\r
+  return os.str();\r
+}\r
+//---------------------------------------------------------------------------\r
+string\r
+QPauliX::GetSaveText(void) {\r
+  ostringstream os;\r
+  os << X << "," << Y << "," << Name << ",\"\"";\r
+  return os.str();\r
+}\r
+//--------------------------------------------------------------------------\r
+void\r
+QPauliX::Reverse(int y) {\r
+  Y = y - Y;\r
+}\r
+//--------------------------------------------------------------------------\r
+TRect\r
+QPauliX::GetOccupiedRect() {\r
+  return TRect(X, Y, X + 1, Y + 1);\r
+}\r
+//--------------------------------------------------------------------------\r
+\r
diff --git a/circuits/QPauliX.h b/circuits/QPauliX.h
new file mode 100644 (file)
index 0000000..9f8364f
--- /dev/null
@@ -0,0 +1,24 @@
+//---------------------------------------------------------------------------\r
+#ifndef QPauliXH\r
+#define QPauliXH\r
+//---------------------------------------------------------------------------\r
+#include "QCircuit.h"\r
+//---------------------------------------------------------------------------\r
+class QPauliX : public QCircuit {\r
+\r
+public:\r
+  QPauliX(int x, int y);\r
+\r
+  virtual int        GetType(void)    { return QC_PAULIX; }\r
+  virtual string GetTypeStr(void) { return "QPauliX"; }\r
+\r
+  void Draw(QDraw * qDraw);\r
+  void DrawPS(QPSDraw * psDraw);\r
+  string GetCalcText(void);\r
+  string GetSaveText(void);\r
+  void Reverse(int y);\r
+  TRect GetOccupiedRect();\r
+  QCircuit *Clone() {QPauliX *qx = new QPauliX(X, Y); return (QCircuit*)qx;};\r
+};\r
+//---------------------------------------------------------------------------\r
+#endif\r
diff --git a/circuits/QPauliY.cpp b/circuits/QPauliY.cpp
new file mode 100644 (file)
index 0000000..8dfe954
--- /dev/null
@@ -0,0 +1,68 @@
+//---------------------------------------------------------------------------\r
+#include "QPauliY.h"\r
+//---------------------------------------------------------------------------\r
+QPauliY::QPauliY(int x, int y) : QCircuit(x,y) {\r
+  Name = GetTypeStr();\r
+}\r
+//---------------------------------------------------------------------------\r
+void\r
+QPauliY::Draw(QDraw* qDraw) {\r
+\r
+  int GridSize = qDraw->GetGridSize();\r
+  int UnitSize = qDraw->GetUnitSize();\r
+  int d = (GridSize-UnitSize)/2;\r
+  int x1 = X * GridSize+d;\r
+  int y1 = Y * GridSize+d;\r
+  int x2 = x1 + UnitSize;\r
+  int y2 = y1 + UnitSize;\r
+\r
+  qDraw->SetBrushColor(clWhite);\r
+  qDraw->FillRect(x1,y1,x2,y2);\r
+  qDraw->SetBrushColor(clLime);\r
+  qDraw->FrameRect(x1,y1,x2,y2);\r
+\r
+  qDraw->SetBrushColor(clWhite);\r
+  qDraw->TextOut(x1+UnitSize/2,y1+UnitSize/2,"Y");\r
+}\r
+//---------------------------------------------------------------------------\r
+void\r
+QPauliY::DrawPS(QPSDraw * psDraw) {\r
+\r
+  int GridSize = psDraw->GetGridSize();\r
+  int UnitSize = psDraw->GetUnitSize();\r
+  int d = (GridSize-UnitSize)/2;\r
+  int x1 = X * GridSize+d;\r
+  int y1 = Y * GridSize+d;\r
+  int x2 = x1 + UnitSize;\r
+  int y2 = y1 + UnitSize;\r
+\r
+  psDraw->FillRect(x1,y1,x2,y2);\r
+  psDraw->FrameRect(x1,y1,x2,y2);\r
+  psDraw->TextOut(x1+UnitSize/2,y1+UnitSize/2,"Y");\r
+}\r
+//---------------------------------------------------------------------------\r
+string\r
+QPauliY::GetCalcText(void) {\r
+  ostringstream os;\r
+  os << "PAULIY(q[" << Y << "])";\r
+  return os.str();\r
+}\r
+//---------------------------------------------------------------------------\r
+string\r
+QPauliY::GetSaveText(void) {\r
+  ostringstream os;\r
+  os << X << "," << Y << "," << Name << ",\"\"";\r
+  return os.str();\r
+}\r
+//--------------------------------------------------------------------------\r
+void\r
+QPauliY::Reverse(int y) {\r
+  Y = y - Y;\r
+}\r
+//--------------------------------------------------------------------------\r
+TRect\r
+QPauliY::GetOccupiedRect() {\r
+  return TRect(X, Y, X + 1, Y + 1);\r
+}\r
+//--------------------------------------------------------------------------\r
+\r
diff --git a/circuits/QPauliY.h b/circuits/QPauliY.h
new file mode 100644 (file)
index 0000000..2efe8d5
--- /dev/null
@@ -0,0 +1,23 @@
+//---------------------------------------------------------------------------\r
+#ifndef QPauliYH\r
+#define QPauliYH\r
+//---------------------------------------------------------------------------\r
+#include "QCircuit.h"\r
+//---------------------------------------------------------------------------\r
+class QPauliY : public QCircuit {\r
+public :\r
+  QPauliY(int x, int y);\r
+\r
+  virtual int        GetType(void)    { return QC_PAULIY; }\r
+  virtual string GetTypeStr(void) { return "QPauliY"; }\r
+\r
+  void Draw(QDraw *qDraw);\r
+  void DrawPS(QPSDraw *psDraw);\r
+  string GetCalcText(void);\r
+  string GetSaveText(void);\r
+  void Reverse(int y);\r
+  TRect GetOccupiedRect();\r
+  QCircuit *Clone() {QPauliY *qy = new QPauliY(X, Y); return (QCircuit*)qy;};\r
+};\r
+//---------------------------------------------------------------------------\r
+#endif\r
diff --git a/circuits/QPauliZ.cpp b/circuits/QPauliZ.cpp
new file mode 100644 (file)
index 0000000..255fac2
--- /dev/null
@@ -0,0 +1,68 @@
+//---------------------------------------------------------------------------\r
+#include "QPauliZ.h"\r
+//---------------------------------------------------------------------------\r
+QPauliZ::QPauliZ(int x, int y) : QCircuit(x,y) {\r
+  Name = GetTypeStr();\r
+}\r
+//---------------------------------------------------------------------------\r
+void\r
+QPauliZ::Draw(QDraw* qDraw) {\r
+\r
+  int GridSize = qDraw->GetGridSize();\r
+  int UnitSize = qDraw->GetUnitSize();\r
+  int d = (GridSize-UnitSize)/2;\r
+  int x1 = X * GridSize+d;\r
+  int y1 = Y * GridSize+d;\r
+  int x2 = x1 + UnitSize;\r
+  int y2 = y1 + UnitSize;\r
+\r
+  qDraw->SetBrushColor(clWhite);\r
+  qDraw->FillRect(x1,y1,x2,y2);\r
+  qDraw->SetBrushColor(clLime);\r
+  qDraw->FrameRect(x1,y1,x2,y2);\r
+\r
+  qDraw->SetBrushColor(clWhite);\r
+  qDraw->TextOut(x1+UnitSize/2,y1+UnitSize/2,"Z");\r
+\r
+}\r
+//---------------------------------------------------------------------------\r
+void\r
+QPauliZ::DrawPS(QPSDraw * psDraw) {\r
+  int GridSize = psDraw->GetGridSize();\r
+  int UnitSize = psDraw->GetUnitSize();\r
+  int d = (GridSize-UnitSize)/2;\r
+  int x1 = X * GridSize+d;\r
+  int y1 = Y * GridSize+d;\r
+  int x2 = x1 + UnitSize;\r
+  int y2 = y1 + UnitSize;\r
+\r
+  psDraw->FillRect(x1,y1,x2,y2);\r
+  psDraw->FrameRect(x1,y1,x2,y2);\r
+\r
+  psDraw->TextOut(x1+UnitSize/2,y1+UnitSize/2,"Z");\r
+}\r
+//---------------------------------------------------------------------------\r
+string\r
+QPauliZ::GetCalcText(void) {\r
+  ostringstream os;\r
+  os << "PAULIZ(q[" << Y << "])";\r
+  return os.str();\r
+}\r
+//---------------------------------------------------------------------------\r
+string\r
+QPauliZ::GetSaveText(void) {\r
+  ostringstream os;\r
+  os << X << "," << Y << "," << Name << ",\"\"";\r
+  return os.str();\r
+}\r
+//--------------------------------------------------------------------------\r
+void\r
+QPauliZ::Reverse(int y) {\r
+  Y = y - Y;\r
+}\r
+//--------------------------------------------------------------------------\r
+TRect\r
+QPauliZ::GetOccupiedRect() {\r
+  return TRect(X, Y, X + 1, Y + 1);\r
+}\r
+//--------------------------------------------------------------------------\r
diff --git a/circuits/QPauliZ.h b/circuits/QPauliZ.h
new file mode 100644 (file)
index 0000000..8b8422a
--- /dev/null
@@ -0,0 +1,23 @@
+//---------------------------------------------------------------------------\r
+#ifndef QPauliZH\r
+#define QPauliZH\r
+//---------------------------------------------------------------------------\r
+#include "QCircuit.h"\r
+//---------------------------------------------------------------------------\r
+class QPauliZ : public QCircuit {\r
+public :\r
+  QPauliZ(int x, int y);\r
+\r
+  virtual int        GetType(void)    { return QC_PAULIZ; }\r
+  virtual string GetTypeStr(void) { return "QPauliZ"; }\r
+\r
+  void Draw(QDraw *qDraw);\r
+  void DrawPS(QPSDraw *psDraw);\r
+  string GetCalcText(void);\r
+  string GetSaveText(void);\r
+  void Reverse(int y);\r
+  TRect GetOccupiedRect();\r
+  QCircuit *Clone() {QPauliZ *qz = new QPauliZ(X, Y); return (QCircuit*)qz;};\r
+};\r
+//---------------------------------------------------------------------------\r
+#endif\r
diff --git a/circuits/QRot.cpp b/circuits/QRot.cpp
new file mode 100644 (file)
index 0000000..8885d4d
--- /dev/null
@@ -0,0 +1,90 @@
+//---------------------------------------------------------------------------\r
+// Z Rotation\r
+//---------------------------------------------------------------------------\r
+#include <stdlib.h>\r
+#include "QRot.h"\r
+//---------------------------------------------------------------------------\r
+QRot::QRot(int x,int y) :QCircuit(x,y) {\r
+  Name = GetTypeStr();\r
+  Phase = 0;\r
+}\r
+//---------------------------------------------------------------------------\r
+QRot::QRot(int x,int y, string Param) :QCircuit(x,y) {\r
+  Name = GetTypeStr();\r
+  Phase = atof(Param.c_str());\r
+}\r
+//---------------------------------------------------------------------------\r
+void\r
+QRot::Draw(QDraw *qDraw) {\r
+  int GridSize = qDraw->GetGridSize();\r
+  int UnitSize = qDraw->GetUnitSize();\r
+\r
+  int d = (GridSize-UnitSize)/2;\r
+  int x1 = X * GridSize+d;\r
+  int y1 = Y * GridSize+d;\r
+  int x2 = x1 + UnitSize;\r
+  int y2 = y1 + UnitSize;\r
+\r
+  qDraw->SetBrushColor(clWhite);\r
+  qDraw->FillRect(x1,y1,x2,y2);\r
+  qDraw->SetBrushColor(clPurple);\r
+  qDraw->FrameRect(x1,y1,x2,y2);\r
+  qDraw->SetPenColor(clBlack);\r
+  qDraw->SetBrushColor(clWhite);\r
+  ostringstream os;\r
+  os << Phase;\r
+  qDraw->TextOut(x1+UnitSize/2,y1+UnitSize/2, os.str());\r
+}\r
+//---------------------------------------------------------------------------\r
+void\r
+QRot::Reverse(int y) {\r
+  Y = y-Y;\r
+}\r
+//---------------------------------------------------------------------------\r
+string\r
+QRot::GetCalcText(void) {\r
+  ostringstream os;\r
+  os << "ROT(";\r
+  os << "q[" << Y << "],";\r
+  os << Phase << ")";\r
+  return os.str();\r
+}\r
+//---------------------------------------------------------------------------\r
+void\r
+QRot::DrawPS(QPSDraw *psDraw) {\r
+  int GridSize = psDraw->GetGridSize();\r
+  int UnitSize = psDraw->GetUnitSize();\r
+\r
+  int d = (GridSize-UnitSize)/2;\r
+  int x1 = X * GridSize+d;\r
+  int y1 = Y * GridSize+d;\r
+  int x2 = x1 + UnitSize;\r
+  int y2 = y1 + UnitSize;\r
+\r
+  psDraw->FillRect(x1,y1,x2,y2);\r
+\r
+  psDraw->FillRect(x1,y1,x2,y2);\r
+  psDraw->FrameRect(x1,y1,x2,y2);\r
+  ostringstream os;\r
+  os << Phase;\r
+  psDraw->TextOut(x1+UnitSize/2,y1+UnitSize/2,os.str());\r
+}\r
+//---------------------------------------------------------------------------\r
+string\r
+QRot::GetParam(void) {\r
+  ostringstream os;\r
+  os << Phase;\r
+  return os.str();\r
+}\r
+//---------------------------------------------------------------------------\r
+TRect QRot::GetOccupiedRect() {\r
+  return TRect(X, Y, X + 1, Y + 1);\r
+}\r
+//--------------------------------------------------------------------------\r
+QCircuit *\r
+QRot::Clone() {\r
+  QRot * qc = new QRot(X, Y);\r
+  qc->SetPhase(GetPhase());\r
+  return (QCircuit*)qc;\r
+}\r
+//---------------------------------------------------------------------------\r
diff --git a/circuits/QRot.h b/circuits/QRot.h
new file mode 100644 (file)
index 0000000..c7682b6
--- /dev/null
@@ -0,0 +1,36 @@
+//---------------------------------------------------------------------------\r
+#ifndef QRotH\r
+#define QRotH\r
+//---------------------------------------------------------------------------\r
+#include "QCircuit.h"\r
+//---------------------------------------------------------------------------\r
+class QRot : public QCircuit {\r
+private:\r
+\r
+  double Phase; // Angle (Degree)\r
+\r
+public:\r
+  QRot(int x,int y);\r
+  QRot(int x,int y, string Param);\r
+\r
+  virtual int GetType(void)    { return QC_ROT; }\r
+  virtual string GetTypeStr(void) { return "QRot"; }\r
+\r
+  string GetCalcText(void);\r
+\r
+  void Draw(QDraw *Draw);\r
+  void DrawPS(QPSDraw *psDraw);\r
+  string GetParam(void);\r
+  void Reverse(int y);\r
+  TRect GetOccupiedRect();\r
+  QCircuit *Clone();\r
+  double GetPhase(void){\r
+    return Phase;\r
+  };\r
+  void SetPhase(double p){\r
+    Phase = p;\r
+  };\r
+};\r
+//---------------------------------------------------------------------------\r
+\r
+#endif\r
diff --git a/circuits/QSwap.cpp b/circuits/QSwap.cpp
new file mode 100644 (file)
index 0000000..3dc72da
--- /dev/null
@@ -0,0 +1,117 @@
+//---------------------------------------------------------------------------\r
+#include "QSwap.h"\r
+#include "StrUtils.h"\r
+//---------------------------------------------------------------------------\r
+QSwap::QSwap(int x,int y) :QCircuit(x,y) {\r
+  Name = GetTypeStr();\r
+  Target1 = Y;\r
+  Target2 = Y;\r
+}\r
+//---------------------------------------------------------------------------\r
+QSwap::QSwap(int x,int y, string param) :QCircuit(x,y) {\r
+  Name = GetTypeStr();\r
+  Target1 = Y;\r
+  Target2 = Y;\r
+  vector<string> v = StrUtils::split_str(param);\r
+  Target1 = atoi(v[0].c_str());\r
+  Target2 = atoi(v[1].c_str());\r
+}\r
+//---------------------------------------------------------------------------\r
+void QSwap::SetTarget(int t1, int t2) {\r
+  if (t1 < t2) {\r
+    Target1 = t1;\r
+    Target2 = t2;\r
+  } else {\r
+    Target1 = t2;\r
+    Target2 = t1;\r
+  }\r
+  Y = Target1;\r
+}\r
+//---------------------------------------------------------------------------\r
+void QSwap::Draw(QDraw *qDraw) {\r
+  int GridSize = qDraw->GetGridSize();\r
+  int UnitSize = qDraw->GetUnitSize();\r
+\r
+  int tx = X*GridSize + GridSize/2;\r
+  int ty1 = Target1*GridSize + GridSize/2;\r
+  int ty2 = Target2*GridSize + GridSize/2;\r
+  qDraw->SetPenColor(clBlack);\r
+  qDraw->DrawLine(tx,ty1,tx,ty2);\r
+\r
+  int d  = (GridSize - UnitSize) / 2;\r
+  int x1 = X * GridSize+d;\r
+  int y1 = Target1 * GridSize+d;\r
+  int x2 = x1 + UnitSize;\r
+  int y2 = y1 + UnitSize;\r
+\r
+  qDraw->SetPenColor(clBlack);\r
+  qDraw->DrawLine(x1, y1, x2, y2);\r
+  qDraw->DrawLine(x1, y2, x2, y1);\r
+\r
+  y1 = Target2 * GridSize + d;\r
+  y2 = y1 + UnitSize;\r
+\r
+  qDraw->SetPenColor(clBlack);\r
+  qDraw->DrawLine(x1, y1, x2, y2);\r
+  qDraw->DrawLine(x1, y2, x2, y1);\r
+}\r
+//---------------------------------------------------------------------------\r
+string\r
+QSwap::GetCalcText(void) {\r
+  ostringstream os;\r
+  os << "SWAP(";\r
+  os << "q[" << Target1 << "],";\r
+  os << "q[" << Target2 << "])";\r
+  return os.str();\r
+}\r
+//---------------------------------------------------------------------------\r
+void QSwap::DrawPS(QPSDraw *psDraw) {\r
+  int GridSize = psDraw->GetGridSize();\r
+  int UnitSize = psDraw->GetUnitSize();\r
+\r
+  int tx1 = X*GridSize + GridSize/2;\r
+\r
+  int ty1 = Target1*GridSize + GridSize/2;\r
+  int ty2 = Target2*GridSize + GridSize/2;\r
+  psDraw->DrawLine(tx1,ty1,tx1,ty2);\r
+\r
+\r
+  int d = (GridSize-UnitSize)/2;\r
+  int x1 = X * GridSize+d;\r
+  int y1 = Target1 * GridSize+d;\r
+  int x2 = x1 + UnitSize;\r
+  int y2 = y1 + UnitSize;\r
+\r
+  psDraw->DrawLine(x1, y1, x2, y2);\r
+  psDraw->DrawLine(x1, y2, x2, y1);\r
+\r
+  y1 = Target2 * GridSize;\r
+  y2 = y1 + UnitSize;\r
+\r
+  psDraw->DrawLine(x1, y1, x2, y2);\r
+  psDraw->DrawLine(x1, y2, x2, y1);\r
+}\r
+//---------------------------------------------------------------------------\r
+string\r
+QSwap::GetParam(void) {\r
+  ostringstream os;\r
+  os << Target1 << "," << Target2;\r
+  return os.str();\r
+}\r
+//---------------------------------------------------------------------------\r
+void QSwap::Reverse(int y) {\r
+  Y = y - Y;\r
+  Target1 = y - Target1;\r
+  Target2 = y - Target2;\r
+}\r
+//---------------------------------------------------------------------------\r
+TRect QSwap::GetOccupiedRect() {\r
+  return TRect(X, Target1, X + 1, Target2 + 1);\r
+}\r
+//---------------------------------------------------------------------------\r
+QCircuit *QSwap::Clone() {\r
+  QSwap * qs = new QSwap(X, Y);\r
+  qs->SetTarget(this->GetTarget1(), this->GetTarget2());\r
+  return (QCircuit*)qs;\r
+}\r
+//---------------------------------------------------------------------------\r
diff --git a/circuits/QSwap.h b/circuits/QSwap.h
new file mode 100644 (file)
index 0000000..fd8a1ee
--- /dev/null
@@ -0,0 +1,35 @@
+//---------------------------------------------------------------------------\r
+#ifndef QSwapH\r
+#define QSwapH\r
+//---------------------------------------------------------------------------\r
+#include "QCircuit.h"\r
+//---------------------------------------------------------------------------\r
+class QSwap : public QCircuit {\r
+private:\r
+\r
+  int Target1;\r
+  int Target2;\r
+\r
+public:\r
+  QSwap(int x,int y);\r
+  QSwap(int x,int y, string Param);\r
+\r
+  virtual int        GetType(void)    { return QC_SWAP; }\r
+  virtual string GetTypeStr(void) { return "QSwap"; }\r
+\r
+  string GetCalcText(void);\r
+\r
+  void SetTarget(int t1, int t2);\r
+  int GetTarget1(void) {return Target1;};\r
+  int GetTarget2(void) {return Target2;};\r
+\r
+\r
+  void Draw(QDraw *Draw);\r
+  void DrawPS(QPSDraw *psDraw);\r
+  string GetParam(void);\r
+  void Reverse(int y);\r
+  TRect GetOccupiedRect();\r
+  QCircuit *Clone();\r
+};\r
+//--------------------------------------------------------------------------\r
+#endif\r
diff --git a/circuits/QWalsh.cpp b/circuits/QWalsh.cpp
new file mode 100644 (file)
index 0000000..6d8fe29
--- /dev/null
@@ -0,0 +1,67 @@
+//---------------------------------------------------------------------------\r
+// Hadamard Gate\r
+//---------------------------------------------------------------------------\r
+#include "QWalsh.h"\r
+//---------------------------------------------------------------------------\r
+QWalsh::QWalsh(int x,int y) :QCircuit(x,y) {\r
+  Name = GetTypeStr();\r
+}\r
+//---------------------------------------------------------------------------\r
+void\r
+QWalsh::Draw(QDraw *qDraw) {\r
+  int GridSize = qDraw->GetGridSize();\r
+  int UnitSize = qDraw->GetUnitSize();\r
+  int d = (GridSize-UnitSize)/2;\r
+  int x1 = X * GridSize+d;\r
+  int y1 = Y * GridSize+d;\r
+  int x2 = x1 + UnitSize;\r
+  int y2 = y1 + UnitSize;\r
+\r
+  qDraw->SetBrushColor(clWhite);\r
+  qDraw->FillRect(x1,y1,x2,y2);\r
+  qDraw->SetBrushColor(clRed);\r
+  qDraw->FrameRect(x1,y1,x2,y2);\r
+\r
+  qDraw->SetBrushColor(clWhite);\r
+  qDraw->TextOut(x1+UnitSize/2,y1+UnitSize/2,"H");\r
+}\r
+//---------------------------------------------------------------------------\r
+string\r
+QWalsh::GetCalcText(void) {\r
+  ostringstream os;\r
+  os << "H(q[" << Y << "])";\r
+  return os.str();\r
+}\r
+//---------------------------------------------------------------------------\r
+void\r
+QWalsh::DrawPS(QPSDraw *psDraw) {\r
+  int GridSize = psDraw->GetGridSize();\r
+  int UnitSize = psDraw->GetUnitSize();\r
+  int d = (GridSize-UnitSize)/2;\r
+  int x1 = X * GridSize+d;\r
+  int y1 = Y * GridSize+d;\r
+  int x2 = x1 + UnitSize;\r
+  int y2 = y1 + UnitSize;\r
+\r
+  psDraw->FillRect(x1,y1,x2,y2);\r
+  psDraw->FrameRect(x1,y1,x2,y2);\r
+  psDraw->TextOut(x1+UnitSize/2,y1+UnitSize/2,"H");\r
+}\r
+//---------------------------------------------------------------------------\r
+void\r
+QWalsh::Reverse(int y) {\r
+  Y = y - Y;\r
+}\r
+//---------------------------------------------------------------------------\r
+TRect\r
+QWalsh::GetOccupiedRect() {\r
+  return TRect(X, Y, X + 1, Y + 1);\r
+}\r
+//---------------------------------------------------------------------------\r
+QCircuit *\r
+QWalsh::Clone() {\r
+  QWalsh *qw = new QWalsh(X, Y);\r
+  return (QCircuit*)qw;\r
+}\r
+//---------------------------------------------------------------------------\r
+\r
diff --git a/circuits/QWalsh.h b/circuits/QWalsh.h
new file mode 100644 (file)
index 0000000..1a95924
--- /dev/null
@@ -0,0 +1,24 @@
+//---------------------------------------------------------------------------\r
+#ifndef QWalshH\r
+#define QWalshH\r
+//---------------------------------------------------------------------------\r
+#include "QCircuit.h"\r
+//---------------------------------------------------------------------------\r
+class QWalsh : public QCircuit {\r
+private:\r
+\r
+public:\r
+  QWalsh(int x,int y);\r
+\r
+  virtual int        GetType(void)    { return QC_WALSH; }\r
+  virtual string GetTypeStr(void) { return "QWalsh"; }\r
+\r
+  void Draw(QDraw *Draw);\r
+  string GetCalcText(void);\r
+  void DrawPS(QPSDraw *psDraw);\r
+  void Reverse(int y);\r
+  TRect GetOccupiedRect();\r
+  QCircuit *Clone();\r
+};\r
+//---------------------------------------------------------------------------\r
+#endif\r
diff --git a/circuits/makefile b/circuits/makefile
new file mode 100644 (file)
index 0000000..e778ea1
--- /dev/null
@@ -0,0 +1,3 @@
+clean:
+       rm -f *.obj
+       rm -f *.~*
diff --git a/compiler/000.txt b/compiler/000.txt
new file mode 100644 (file)
index 0000000..4d5411e
--- /dev/null
@@ -0,0 +1,17 @@
+2005/10/11\r
+\81E\90V\82µ\82¢\83Q\81[\83g\82Ì\92Ç\89Á\95û\96@\r
+\81@\81E\82Ü\82¸\81A /calcunits/QC_??.cpp\82ð\8dì\82Á\82Ä\92Ç\89Á\82·\82é\81B\r
+\81@\81EQCompiler.cpp\82Ì const QCompiler::QGATES QCompiler::qgates[] \82É\92Ç\89Á\81B\r
+\81@\81EQCompiler.h\82Ìtypedef enum _commandnumber\82É\81A\91Î\89\9e\82·\82é\8f\87\94Ô\82É\92Ç\89Á\r
+\81@\81EQCalcUnit *\r
+\81@QCompilerCntl::AllocateControl(const unsigned int index)\r
+\81@\82É\93®\8dì\82ð\92Ç\89Á\81B\r
+\81@\81Eqclib \82Ìmakefile\82É\92Ç\89Á\r
+\r
+2005/05/18\r
+\83R\83\93\83p\83C\83\8b\83I\83v\83V\83\87\83\93\r
+\r
+% g++ qcctmp.cpp -I../qclib -I../calcunits ../qclib/qclib.a\r
+\r
+\82Ü\82¸\82Íqclib.a \82ÉQCalcUnits\82ð\82·\82×\82Ä\83\8a\83\93\83N\82·\82é\81B\r
+\81¨\82µ\82½\r
diff --git a/compiler/QCompiler.cpp b/compiler/QCompiler.cpp
new file mode 100644 (file)
index 0000000..12f2bb6
--- /dev/null
@@ -0,0 +1,278 @@
+//----------------------------------------------------------------------------\r
+//  QCompiler.cpp\r
+//  Compile intermediate codes\r
+//  $Date: 2003/01/17 19:37:43 $\r
+//  $Revision: 1.3 $\r
+//----------------------------------------------------------------------------\r
+#ifdef __BORLANDC__\r
+#include <vcl.h>\r
+#pragma hdrstop\r
+#endif //__BORLANDC__\r
+\r
+#include <iostream>\r
+#include <vector>\r
+#include <string>\r
+#include <cstdlib>\r
+#include "QCompiler.h"\r
+#include "QParseInfo.h"\r
+\r
+//----------------------------------------------------------------------------\r
+#ifdef __BORLANDC__\r
+#pragma package(smart_init)\r
+#endif //__BORLANDC__\r
+\r
+using namespace std;\r
+\r
+//----------------------------------------------------------------------------\r
+//  Syntax of intermediate code  (see also `QCompiler.h')\r
+//----------------------------------------------------------------------------\r
+const char  QCompiler::OP_BRA    = '(';\r
+const char  QCompiler::OP_KET    = ')';\r
+const char  QCompiler::QB_BRA    = '[';\r
+const char  QCompiler::QB_KET    = ']';\r
+const char  QCompiler::DELIM     = ',';\r
+\r
+const QCompiler::QGATES QCompiler::qgates[] = {\r
+  {"CNOT" ,2,{ at_qbit, at_qbit, at_null}},\r
+  {"ROT"  ,2,{ at_qbit, at_real, at_null}},\r
+  {"CROT" ,3,{ at_qbit, at_qbit, at_real}},\r
+  {"H"    ,1,{ at_qbit, at_null, at_null}},\r
+  {"MEASURE"    ,1,{ at_qbit, at_null, at_null}},\r
+  {"SWAP" ,2,{ at_qbit, at_qbit, at_null}},\r
+  {"PAULIX"    ,1,{ at_qbit, at_null, at_null}},\r
+  {"PAULIY"    ,1,{ at_qbit, at_null, at_null}},\r
+  {"PAULIZ"    ,1,{ at_qbit, at_null, at_null}},\r
+  {"NOT"  ,1,{ at_qbit, at_null, at_null}},\r
+  {"CCNOT",3,{ at_qbit, at_qbit, at_qbit}},\r
+  {"INIT" ,1,{ at_real, at_null, at_null}}\r
+};\r
+\r
+const int QCompiler::opn_max = sizeof(QCompiler::qgates)/sizeof(QCompiler::QGATES);\r
+\r
+//----------------------------------------------------------------------------\r
+/**\r
+ *  Constructor\r
+ */\r
+QCompiler::QCompiler(void) {\r
+  mError = false;\r
+  mState = false;\r
+}\r
+//----------------------------------------------------------------------------\r
+/**\r
+ *  Constructor with input stream\r
+ */\r
+QCompiler::QCompiler(std::istream &is) {\r
+  mError = false;\r
+  mState = false;\r
+  ReadFromStream(is);\r
+}\r
+//----------------------------------------------------------------------------\r
+/**\r
+ *  Destructor\r
+ */\r
+QCompiler::~QCompiler() {\r
+}\r
+//----------------------------------------------------------------------------\r
+/**\r
+ *  Read intermediate code from stream\r
+ */\r
+void\r
+QCompiler::ReadFromStream(std::istream &is) {\r
+  char        c1;\r
+  std::string st1    = "";\r
+  int         nlcode = -1; // -1:unknown 0:CR+LF 1:LF+CR 2:CR 3:LF\r
+\r
+  mLines.clear();\r
+  mError = mState = false;\r
+\r
+  while (!is.eof()) {\r
+    is.read(&c1, 1);\r
+    if (c1 == 0x0d || c1 == 0x0a) {\r
+      switch (nlcode) {\r
+      case -1: // unknown\r
+        if (c1 == 0x0d) {\r
+          if (0x0a == is.peek()) {\r
+            nlcode = 0;\r
+          } else {\r
+            nlcode = 2;\r
+            goto push;\r
+          }\r
+        } else  {// c1 == 0x0a\r
+          if (0x0d == is.peek()) {\r
+            nlcode = 1;\r
+          } else {\r
+            nlcode = 3;\r
+            goto push;\r
+          }\r
+        }\r
+      case 0:\r
+      case 1:\r
+        is.read(&c1, 1); // skip one char\r
+      case 2:\r
+      case 3:\r
+push:\r
+        mLines.push_back(st1);\r
+        st1 = "";\r
+        break;\r
+      default:\r
+        break;\r
+      }\r
+    } else {\r
+      st1 += c1;\r
+    }\r
+  }\r
+}\r
+//----------------------------------------------------------------------------\r
+/**\r
+ *  Compile\r
+ */\r
+bool\r
+QCompiler::Compile(void) {\r
+  int         i, vec_size = mLines.size();\r
+  for (i = 0; i < vec_size; i++) {\r
+    if (mLines[i].length() == 0 || mLines[i][0] == '#') {\r
+      // skip\r
+      continue;\r
+    }\r
+    QParseInfo pinfo = ParseOneLine(mLines[i]);\r
+    try {\r
+      if (!CompileOneLine(pinfo)) throw pinfo;\r
+    } catch (QParseInfo einfo) {\r
+      mError = true;\r
+      CatchError(einfo, i); // is abstract virtual member\r
+      break;\r
+    }\r
+  }\r
+  mState = true;\r
+  return !mError;\r
+}\r
+//----------------------------------------------------------------------------\r
+/**\r
+ *  Parser\r
+ */\r
+QParseInfo\r
+QCompiler::ParseOneLine(const std::string &strline) const {\r
+  int                         i, j;   // tmp\r
+  std::string                 s1, s2; // tmp\r
+  std::vector<std::string>    args;\r
+  int                         comint;\r
+  std::vector<int>            targets;\r
+  double                      rotation = 0;\r
+\r
+  // Com(Arg)\r
+  if (!ExtractComArg(strline, OP_BRA, OP_KET, s1, s2)) {\r
+    return QParseInfo(QParseInfo::er_syntax_error);\r
+  }\r
+\r
+  // Extract aa, bb, and cc from "aa,bb,cc"\r
+  if (!ExtractField(s2, DELIM, args)) {\r
+    // discard s2\r
+    return QParseInfo(QParseInfo::er_syntax_error);\r
+  }\r
+\r
+  // Get command number from command string\r
+  if ((comint = GetComint(s1)) == -1) {\r
+    // discard s1\r
+    return QParseInfo(QParseInfo::er_unknown_operation);\r
+  }\r
+\r
+  j = args.size();\r
+  if (j < qgates[comint].arg_num) {\r
+    return QParseInfo(QParseInfo::er_lack_of_arguments);\r
+  }\r
+  if (j > qgates[comint].arg_num) {\r
+    return QParseInfo(QParseInfo::er_too_many_arguments);\r
+  }\r
+\r
+  for (i = 0; i < j; i++) {\r
+    switch (qgates[comint].arg_types[i]) {\r
+    case at_qbit:\r
+      if (ExtractComArg(args[i], QB_BRA, QB_KET, s1, s2) && s1 == "q" && s2 != "") {\r
+        targets.push_back(std::atoi(s2.c_str()));\r
+      } else {\r
+        return QParseInfo(QParseInfo::er_invalid_arguments);\r
+      }\r
+      break;\r
+    case at_real:\r
+      rotation = std::atof(args[i].c_str());\r
+      targets.push_back(std::atof(args[i].c_str()));\r
+    case at_oprt:\r
+      break;\r
+    default:\r
+      break;\r
+    }\r
+  }\r
+  return QParseInfo(comint, targets, rotation);\r
+}\r
+//----------------------------------------------------------------------------\r
+/**\r
+ *  ex) bra = '[', ket = ']', strline = "q[20]" --> get "q" and "20" as string\r
+ *      bra = '(', ket = ')', strline = CNOT(q[0],q[1])\r
+ *       --> get "CNOT" and "q[0],q[1]" as string\r
+ */\r
+bool\r
+QCompiler::ExtractComArg(const std::string &strline, const char bra, const char ket,\r
+                         std::string &Com,\r
+                         std::string &Arg) const {\r
+  int pos_bra = strline.find(bra);\r
+  int pos_ket = strline.find(ket);\r
+  int length  = strline.length();\r
+\r
+  Com = Arg = "";\r
+  if (pos_bra < 1 || pos_ket - pos_bra < 1 || pos_ket != length - 1) {\r
+    return false;\r
+  }\r
+  Com = strline.substr(0, pos_bra);\r
+  if (pos_ket - pos_bra >= 2) {\r
+    Arg = strline.substr(pos_bra + 1, pos_ket - pos_bra - 1);\r
+  }\r
+  return true;\r
+}\r
+//----------------------------------------------------------------------------\r
+/**\r
+ *  Null field is not allowd, but "" (zero string) is OK.\r
+ *\r
+ *  ex) delim = ',', strline = "q[0],q[4],10"\r
+ *       --> get "q[0]", "q[4]" and "10" as vector<string>, and return true\r
+ *      delim = ',', strline = "aa,,bb" (having null field between aa and bb)\r
+ *       --> return false\r
+ *      delim = ',', strline = ""\r
+ *       --> return true\r
+ */\r
+bool\r
+QCompiler::ExtractField(const std::string &strline, const char delim,\r
+                        std::vector<std::string> &Args) const {\r
+  int i;\r
+  int fpos = 0;\r
+  int length = strline.length();\r
+  std::string s1 = "";\r
+\r
+  Args.clear();\r
+  for (i = 0; i < length; i++) {\r
+    if (strline.at(i) == delim) {\r
+      if (i > fpos) {\r
+        Args.push_back(s1);\r
+        s1 = "";\r
+        fpos = i + 1;\r
+      } else {\r
+        return false;\r
+      }\r
+    } else {\r
+      s1 += strline.at(i);\r
+    }\r
+  }\r
+  if (s1.length() > 0) {\r
+    Args.push_back(s1);\r
+  }\r
+  return true;\r
+}\r
+//----------------------------------------------------------------------------\r
+/**\r
+ *  Get command number from command string\r
+ */\r
+int\r
+QCompiler::GetComint(const std::string &_str) const {\r
+  for (int i = 0; i < opn_max; i++)if (_str == qgates[i].opstr) return i;\r
+  return -1;\r
+}\r
+//----------------------------------------------------------------------------\r
diff --git a/compiler/QCompiler.h b/compiler/QCompiler.h
new file mode 100644 (file)
index 0000000..3b37cf1
--- /dev/null
@@ -0,0 +1,100 @@
+//----------------------------------------------------------------------------\r
+//  QCompiler.h\r
+//  Compile intermediate codes\r
+//  $Date: 2003/01/17 19:37:43 $\r
+//  $Revision: 1.3 $\r
+//----------------------------------------------------------------------------\r
+#ifndef QCOMPILER_H\r
+#define QCOMPILER_H\r
+\r
+#include <iostream>\r
+#include <string>\r
+#include <vector>\r
+#include "QParseInfo.h"\r
+\r
+class QCompiler {\r
+\r
+public:\r
+  QCompiler(void);\r
+  QCompiler(std::istream &is);\r
+  virtual ~QCompiler();\r
+  bool Compile(void);\r
+  void ReadFromStream(std::istream &is);\r
+  bool HasError(void) {\r
+    return mError;\r
+  }\r
+  bool GetState(void) {\r
+    return mState;\r
+  }\r
+\r
+  typedef enum _opnumber {\r
+    opn_arg_max = 3,\r
+    opn_length  = 10\r
+  } OpNumber;\r
+\r
+  static const int opn_max;\r
+\r
+protected:\r
+  virtual bool CompileOneLine(const QParseInfo &pinfo) = 0;\r
+  virtual void CatchError(const QParseInfo &pinfo, const int at) = 0;\r
+\r
+  QParseInfo  ParseOneLine(const std::string &strline) const;\r
+  bool        ExtractComArg(const std::string &strline, const char bra, const char ket,\r
+                            std::string &Com, std::string &Arg) const;\r
+  bool        ExtractField(const std::string &strline, const char delim,\r
+                           std::vector<std::string> &Args) const ;\r
+  int         GetComint(const std::string &_str) const;\r
+\r
+  // Member valuables\r
+  std::vector<std::string>    mLines;\r
+  bool                        mError;\r
+  bool                        mState; // true == finished\r
+\r
+  //------------------------------------------------------------------------\r
+  //  Syntax of intermediate code  (see also `QCompiler.cpp')\r
+  //------------------------------------------------------------------------\r
+  // Argument types\r
+  typedef enum _argtype {\r
+    at_null = 0,\r
+    at_qbit = 1,\r
+    at_real = 2,\r
+    at_oprt = 3\r
+  } ArgType;\r
+\r
+  // Command numbers, each of which corresponds to the index num of OPSTR\r
+\r
+  typedef enum _commandnumber {\r
+    cn_cnot     = 0,\r
+    cn_rot ,\r
+    cn_crot ,\r
+    cn_h    ,\r
+    cn_m    ,\r
+    cn_swap ,\r
+    cn_x    ,\r
+    cn_y    ,\r
+    cn_z    ,\r
+    cn_not  ,\r
+    cn_ccnot,\r
+    cn_init\r
+  } CommandNumber;\r
+\r
+  // Size of array\r
+\r
+\r
+\r
+  struct QGATES {\r
+    char opstr[opn_length];\r
+    int arg_num;\r
+    int arg_types[opn_arg_max];\r
+  };\r
+\r
+  static const QGATES qgates[];\r
+\r
+  static const char   OP_BRA;\r
+  static const char   OP_KET;\r
+  static const char   QB_BRA;\r
+  static const char   QB_KET;\r
+  static const char   DELIM;\r
+};\r
+\r
+#endif //QCOMPILER_H\r
diff --git a/compiler/QCompilerCntl.cpp b/compiler/QCompilerCntl.cpp
new file mode 100644 (file)
index 0000000..df6563a
--- /dev/null
@@ -0,0 +1,134 @@
+//----------------------------------------------------------------------------\r
+//  Compile intermediates into list of the calc units\r
+//----------------------------------------------------------------------------\r
+#ifdef __BORLANDC__\r
+#include <vcl.h>\r
+#pragma hdrstop\r
+#endif //__BORLANDC__\r
+\r
+#include <iostream>\r
+#include <vector>\r
+#include "QCompiler.h"\r
+#include "QCompilerCntl.h"\r
+#include "QParseInfo.h"\r
+#include "QCalcUnit.h"\r
+\r
+#include "QC_not.h"\r
+#include "QC_hadamard.h"\r
+#include "QC_cnot.h"\r
+#include "QC_crot.h"\r
+#include "QC_rot.h"\r
+#include "QC_ccnot.h"\r
+#include "QC_pauliX.h"\r
+#include "QC_pauliY.h"\r
+#include "QC_pauliZ.h"\r
+#include "QC_swap.h"\r
+#include "QC_measure.h"\r
+\r
+// ---------------------------------------------------------------------------\r
+#ifdef __BORLANDC__\r
+#pragma package(smart_init)\r
+#endif //__BORLANDC__\r
+\r
+//----------------------------------------------------------------------------\r
+/**\r
+ *\r
+ */\r
+QCompilerCntl::QCompilerCntl(void) : QCompiler() {\r
+  mNumOfQBits = 0;\r
+  mQParseInfo.clear();\r
+}\r
+//----------------------------------------------------------------------------\r
+/**\r
+ *\r
+ */\r
+QCompilerCntl::QCompilerCntl(std::istream &is) : QCompiler(is) {\r
+  mNumOfQBits = 0;\r
+  mQParseInfo.clear();\r
+}\r
+//----------------------------------------------------------------------------\r
+/**\r
+ *\r
+ */\r
+QCompilerCntl::~QCompilerCntl() {\r
+  mQParseInfo.clear();\r
+}\r
+//----------------------------------------------------------------------------\r
+/**\r
+ *\r
+ */\r
+QCalcUnit *\r
+QCompilerCntl::AllocateControl(const unsigned int index) {\r
+  if (index >= mQParseInfo.size()) {\r
+    return NULL; // Error\r
+  }\r
+  QCalcUnit *cu = NULL;\r
+  const std::vector<int> &targets = mQParseInfo[index].QParseInfo::getTargetIndices();\r
+  switch (mQParseInfo[index].getOperator()) {\r
+  case cn_cnot:\r
+    cu = new QC_cnot(targets[0], targets[1]);\r
+    break;\r
+  case cn_crot:\r
+    cu = new QC_crot(targets[0], targets[1], mQParseInfo[index].getRotation());\r
+    break;\r
+  case cn_rot:\r
+    cu = new QC_rot(targets[0], mQParseInfo[index].getRotation());\r
+    break;\r
+  case cn_h:\r
+    cu = new QC_hadamard(targets[0]);\r
+    break;\r
+  case cn_m:\r
+    cu = new QC_measure(targets[0]);\r
+    break;\r
+  case cn_swap:\r
+    cu = new QC_swap(targets[0], targets[1]);\r
+    break;\r
+  case cn_x:\r
+    cu = new QC_pauliX(targets[0]);\r
+    break;\r
+  case cn_y:\r
+    cu = new QC_pauliY(targets[0]);\r
+    break;\r
+  case cn_z:\r
+    cu = new QC_pauliZ(targets[0]);\r
+    break;\r
+  case cn_not:\r
+    cu = new QC_not(targets[0]);\r
+    break;\r
+  case cn_ccnot:\r
+    cu = new QC_ccnot(targets[0], targets[1], targets[2]);\r
+    break;\r
+  case cn_init:\r
+    mNumOfQBits = targets[0];\r
+  default:\r
+    break;\r
+  }\r
+  return cu;\r
+}\r
+//----------------------------------------------------------------------------\r
+/**\r
+ *\r
+ */\r
+bool\r
+QCompilerCntl::CompileOneLine(const QParseInfo &pinfo) {\r
+  if (!pinfo.getParseResult()) {\r
+    return false;\r
+  }\r
+  mQParseInfo.push_back(pinfo);\r
+  return true;\r
+}\r
+//----------------------------------------------------------------------------\r
+/**\r
+ *\r
+ */\r
+void\r
+QCompilerCntl::CatchError(const QParseInfo &pinfo, const int at) {\r
+#ifdef __BORLANDC__\r
+  //ShowMessage(IntToStr(pinfo.getErrorNo()));\r
+#else\r
+  std::cerr << "Parse error occurred at line " << at << "\n"\r
+            << "Error code = " << pinfo.getErrorNo() << "\n";\r
+#endif //__BORLANDC__\r
+  //TODO:\r
+}\r
+//----------------------------------------------------------------------------\r
diff --git a/compiler/QCompilerCntl.h b/compiler/QCompilerCntl.h
new file mode 100644 (file)
index 0000000..5239615
--- /dev/null
@@ -0,0 +1,38 @@
+//----------------------------------------------------------------------------\r
+//  Compile intermediates into list of the calc units\r
+//----------------------------------------------------------------------------\r
+#ifndef QCOMPILERCNTL_H\r
+#define QCOMPILERCNTL_H\r
+\r
+#include <iostream>\r
+#include <vector>\r
+#include "QCompiler.h"\r
+#include "QParseInfo.h"\r
+#include "QCalcUnit.h"\r
+\r
+class QCompilerCntl : public QCompiler {\r
+protected:\r
+  int mNumOfQBits;\r
+\r
+public:\r
+  QCompilerCntl(void);\r
+  QCompilerCntl(std::istream &is);\r
+  virtual ~QCompilerCntl();\r
+  int GetNumberOfControl(void) {\r
+    return mQParseInfo.size();\r
+  }\r
+  QCalcUnit *AllocateControl(const unsigned int index);\r
+  void Clear(void) {\r
+    mQParseInfo.clear();\r
+  }\r
+  int GetNumberOfQBits(void) {\r
+    return mNumOfQBits;\r
+  }\r
+\r
+protected:\r
+  std::vector<QParseInfo> mQParseInfo;\r
+  virtual bool CompileOneLine(const QParseInfo &pinfo);\r
+  virtual void CatchError(const QParseInfo &pinfo, const int at);\r
+};\r
+\r
+#endif //QCOMPILERCNTL_H\r
diff --git a/compiler/QCompilerCode.cpp b/compiler/QCompilerCode.cpp
new file mode 100644 (file)
index 0000000..587cb07
--- /dev/null
@@ -0,0 +1,255 @@
+//----------------------------------------------------------------------------\r
+//  CompilerCode.cpp\r
+//  Compile intermediate code into native C++ code\r
+//  $Date: 2003/02/20 00:24:16 $\r
+//  $Revision: 1.4 $\r
+//----------------------------------------------------------------------------\r
+#ifdef __BORLANDC__\r
+#include <vcl.h>\r
+#pragma hdrstop\r
+#endif //__BORLANDC__\r
+\r
+#include <iostream>\r
+#include <fstream>\r
+#include "QCompilerCode.h"\r
+\r
+#ifndef M_PI\r
+#define M_PI 3.1415926535897932384626433832795028841971693993751\r
+#endif//M_PI\r
+\r
+//----------------------------------------------------------------------------\r
+#ifdef __BORLANDC__\r
+#pragma package(smart_init)\r
+#endif //__BORLANDC__\r
+\r
+//----------------------------------------------------------------------------\r
+/**\r
+ *  Constructor\r
+ */\r
+QCompilerCode::QCompilerCode(const char * const filename) : QCompiler() {\r
+  mQParseInfo.clear();\r
+  mTargetName = filename;\r
+}\r
+\r
+//----------------------------------------------------------------------------\r
+/**\r
+ *  Constructor with input stream\r
+ */\r
+QCompilerCode::QCompilerCode(std::istream &is, const char * const filename)\r
+    : QCompiler(is) {\r
+  mQParseInfo.clear();\r
+  mTargetName = filename;\r
+}\r
+\r
+//----------------------------------------------------------------------------\r
+/**\r
+ *  Destructor\r
+ */\r
+QCompilerCode::~QCompilerCode() {\r
+  mQParseInfo.clear();\r
+}\r
+\r
+//----------------------------------------------------------------------------\r
+/**\r
+ *  Save the compile result to output stream\r
+ */\r
+void\r
+QCompilerCode::SaveToStream(std::ostream &os) {\r
+  int vec_size = mQParseInfo.size();\r
+\r
+  if (false == mState) {\r
+    std::cerr << "QCompilerCode: compile has not been completed.\n";\r
+    return;\r
+  }\r
+\r
+  WriteHeader(os);\r
+  for (int i = 0; i < vec_size; i++) {\r
+    const std::vector<int> &indices = mQParseInfo[i].getTargetIndices();\r
+    switch (mQParseInfo[i].getOperator()) {\r
+    case cn_cnot:\r
+      WriteCNot(os, indices[0], indices[1]);\r
+      break;\r
+    case cn_crot:\r
+      WriteCRot(os, indices[0], indices[1],\r
+                (double)180 / (double)mQParseInfo[i].getRotation() * M_PI);\r
+      break;\r
+    case cn_h:\r
+      WriteHadam(os, indices[0]);\r
+      break;\r
+    case cn_m:\r
+      // do nothing\r
+      break;\r
+    case cn_swap:\r
+      //TODO:\r
+      break;\r
+    case cn_x:\r
+      //TODO:\r
+      break;\r
+    case cn_y:\r
+      //TODO:\r
+      break;\r
+    case cn_z:\r
+      //TODO:\r
+      break;\r
+    case cn_not:\r
+      //TODO:\r
+      break;\r
+    case cn_ccnot:\r
+      WriteCCNot(os, indices[0], indices[1], indices[2]);\r
+      break;\r
+    case cn_init:\r
+      WriteQBits(os, indices[0]);\r
+      break;\r
+    default:\r
+      break;\r
+    }\r
+  }\r
+  WriteFooter(os);\r
+}\r
+\r
+//----------------------------------------------------------------------------\r
+/**\r
+ *  Save the compile result to a file whose name is specified with 'filename'\r
+ */\r
+void\r
+QCompilerCode::SaveToFile(const char * const filename) {\r
+  std::ofstream   ofs(filename);\r
+\r
+  if (!ofs) {\r
+    std::cerr << "QCompilerCode: failed in file open.\n";\r
+    return;\r
+  }\r
+\r
+  SaveToStream(ofs);\r
+\r
+  ofs.close();\r
+}\r
+\r
+//----------------------------------------------------------------------------\r
+/**\r
+ *  Implementation of a virtual function\r
+ */\r
+bool\r
+QCompilerCode::CompileOneLine(const QParseInfo &pinfo) {\r
+  if (false == pinfo.getParseResult()) return false;\r
+  mQParseInfo.push_back(pinfo);\r
+  return true;\r
+}\r
+\r
+//----------------------------------------------------------------------------\r
+/**\r
+ *  Implementation of a virtual function\r
+ */\r
+void\r
+QCompilerCode::CatchError(const QParseInfo &pinfo, const int at) {\r
+  std::cerr << "There is an error at line " << at << "\n";\r
+  switch (pinfo.getErrorNo()) {\r
+  case QParseInfo::er_syntax_error:\r
+    std::cerr << "Syntax Error.\n";\r
+    break;\r
+  case QParseInfo::er_unknown_operation:\r
+    std::cerr << "Unknown Operation.\n";\r
+    break;\r
+  case QParseInfo::er_lack_of_arguments:\r
+    std::cerr << "Lack of Arguments.\n";\r
+    break;\r
+  case QParseInfo::er_too_many_arguments:\r
+    std::cerr << "Too Many Arguments.\n";\r
+    break;\r
+  case QParseInfo::er_invalid_arguments:\r
+    std::cerr << "Invalid Arguments.\n";\r
+    break;\r
+  default:\r
+    std::cerr << "Unknown Error.\n";\r
+    break;\r
+  }\r
+  mQParseInfo.clear();\r
+}\r
+\r
+//----------------------------------------------------------------------------\r
+/**\r
+ *  Subcontract function of SaveToStream()\r
+ */\r
+void\r
+QCompilerCode::WriteHeader(std::ostream &os) {\r
+  os << "//----------------------------------------------------------------------------\n"\r
+  << "//  QCAD compiled code\n"\r
+  << "//----------------------------------------------------------------------------\n"\r
+  << "#include <iostream>\n"\r
+  << "#include \"QC_all.h\"\n"\r
+  << "#include \"qclib.h\"\n\n"\r
+  << "int main(void)\n{\n"\r
+  << "    std::cerr << \"\\nCopyright (c) 2003 QCAD project.\\n\"\n"\r
+  << "              << \"This application is automatically generated by qcc.\\n\""\r
+  << "              << \"The result will be stored into \\\""\r
+  << mTargetName << "\\\".\\n\\n\";"\r
+  << "\n";\r
+}\r
+\r
+//----------------------------------------------------------------------------\r
+/**\r
+ *  Subcontract function of SaveToStream()\r
+ */\r
+void\r
+QCompilerCode::WriteQBits(std::ostream &os, const int &t1) {\r
+  os << "    QBits qbits(" << t1 << ");\n"\r
+  << "    std::cerr << \"Calcuate with " << t1 << " qubits.\\n\";\n"\r
+  << "    qc::allocWith(qbits);\n";\r
+}\r
+\r
+//----------------------------------------------------------------------------\r
+/**\r
+ *  Subcontract function of SaveToStream()\r
+ */\r
+void\r
+QCompilerCode::WriteFooter(std::ostream &os) {\r
+  os << "    qc::getQBits()->SaveToFile(\"" << mTargetName << "\");\n"\r
+  << "    qc::release();\n\n"\r
+  << "    std::cerr << \"done.\\n\";\n"\r
+  << "    return 0;\n}\n";\r
+}\r
+\r
+//----------------------------------------------------------------------------\r
+/**\r
+ *  Subcontract function of SaveToStream()\r
+ */\r
+void\r
+QCompilerCode::WriteCNot(std::ostream &os, const int &t1, const int &c1) {\r
+  os << "    QC_cnot::calc(" << t1 << ", " << c1 << ",qbits.GetBitsR(),qbits.GetBitsI(),qbits.GetNumberOfQBits());\n"\r
+  << "    std::cerr << \"Controlled-Not(" << t1 << ", " << c1 << ")\\n\";\n";\r
+}\r
+\r
+//----------------------------------------------------------------------------\r
+/**\r
+ *  Subcontract function of SaveToStream()\r
+ */\r
+void\r
+QCompilerCode::WriteCCNot (std::ostream &os, const int &t1,\r
+                           const int &c1, const int &c2) {\r
+  os << "    QC_ccnot::calc(" << t1 << ", " << c1 << ", " << c2 << ",qbits.GetBitsR(),qbits.GetBitsI(),qbits.GetNumberOfQBits());\n"\r
+  << "    std::cerr << \"Toffoli("\r
+  << t1 << ", " << c1 << ", " << c2 << ")\\n\";\n";\r
+}\r
+\r
+//----------------------------------------------------------------------------\r
+/**\r
+ *  Subcontract function of SaveToStream()\r
+ */\r
+void\r
+QCompilerCode::WriteCRot  (std::ostream &os, const int &t1,\r
+                           const int &c1, const double rad) {\r
+  os << "    QC_crot::calc(" << t1 << ", " << c1 << ", " << rad << ",qbits.GetBitsR(),qbits.GetBitsI(),qbits.GetNumberOfQBits());\n"\r
+  << "    std::cerr << \"Controlled-Rot("\r
+  << t1 << ", " << c1 << ")\\n\";\n";\r
+}\r
+\r
+//----------------------------------------------------------------------------\r
+/**\r
+ *  Subcontract function of SaveToStream()\r
+ */\r
+void\r
+QCompilerCode::WriteHadam (std::ostream &os, const int &t1) {\r
+  os << "    QC_hadamard::calc(" << t1 << ",qbits.GetBitsR(),qbits.GetBitsI(),qbits.GetNumberOfQBits());\n"\r
+  << "    std::cerr << \"Hadamard(" << t1 << ")\\n\";\n";\r
+}\r
+\r
diff --git a/compiler/QCompilerCode.h b/compiler/QCompilerCode.h
new file mode 100644 (file)
index 0000000..5d1e80c
--- /dev/null
@@ -0,0 +1,43 @@
+//----------------------------------------------------------------------------\r
+//  CompilerCode.h\r
+//  Compile intermediate code into native C++ code\r
+//  $Date: 2003/02/20 00:24:16 $\r
+//  $Revision: 1.3 $\r
+//----------------------------------------------------------------------------\r
+#ifndef QCOMPILERCODE_H\r
+#define QCOMPILERCODE_H\r
+\r
+#include <iostream>\r
+#include <string>\r
+#include <vector>\r
+#include "QCompiler.h"\r
+#include "QParseInfo.h"\r
+\r
+class QCompilerCode : public QCompiler {\r
+public:\r
+  QCompilerCode(const char * const = "qcpp_result.qdt");\r
+  QCompilerCode(std::istream &is, const char * const = "qcpp_result.qdt");\r
+  virtual ~QCompilerCode();\r
+  void SaveToStream(std::ostream &os);\r
+  void SaveToFile(const char * const filename);\r
+\r
+protected:\r
+  virtual bool CompileOneLine(const QParseInfo &pinfo);\r
+  virtual void CatchError(const QParseInfo &pinfo, const int at);\r
+\r
+  // Utility functions\r
+  void WriteHeader(std::ostream &os);\r
+  void WriteQBits(std::ostream &os, const int &t1);\r
+  void WriteFooter(std::ostream &os);\r
+  void WriteCNot  (std::ostream &os, const int &t1, const int &c1);\r
+  void WriteCCNot (std::ostream &os, const int &t1, const int &c1, const int &c2);\r
+  void WriteCRot  (std::ostream &os, const int &t1, const int &c1, const double rad);\r
+  void WriteHadam (std::ostream &os, const int &t1);\r
+  //TODO: additional controls\r
+\r
+  // Member valuables\r
+  std::string mTargetName;\r
+  std::vector<QParseInfo> mQParseInfo;\r
+};\r
+\r
+#endif //QCOMPILERCODE_H\r
diff --git a/compiler/QParseInfo.cpp b/compiler/QParseInfo.cpp
new file mode 100644 (file)
index 0000000..b71699d
--- /dev/null
@@ -0,0 +1,68 @@
+//----------------------------------------------------------------------------\r
+//  Parse information\r
+//----------------------------------------------------------------------------\r
+#ifdef __BORLANDC__\r
+#include <vcl.h>\r
+#pragma hdrstop\r
+#endif //__BORLANDC__\r
+\r
+#include <iostream>\r
+#include <string>\r
+#include <vector>\r
+#include "QParseInfo.h"\r
+\r
+//----------------------------------------------------------------------------\r
+#ifdef __BORLANDC__\r
+#pragma package(smart_init)\r
+#endif //__BORLANDC__\r
+\r
+\r
+std::vector<int> dummy_vec;\r
+\r
+/**\r
+ *  Constructor\r
+ */\r
+QParseInfo::QParseInfo(const int _operator, const std::vector<int> &_targets,\r
+                       const double _rotation, const bool _result,\r
+                       const int _error) {\r
+  mOperator       = _operator;\r
+  mTargetIndices  = _targets;\r
+  mRotation       = _rotation;\r
+  mParseResult    = _result;\r
+  mErrorNo        = _error;\r
+}\r
+\r
+/**\r
+ *  Constructor for error notification\r
+ */\r
+QParseInfo::QParseInfo(const int _error) {\r
+  mOperator       = -1;\r
+  mTargetIndices  = dummy_vec;\r
+  mRotation       = 0;\r
+  mParseResult    = false;\r
+  mErrorNo        = _error;\r
+}\r
+\r
+/**\r
+ *  Copy constructor\r
+ */\r
+QParseInfo::QParseInfo(const QParseInfo &pinfo) {\r
+  mOperator       = pinfo.mOperator;\r
+  mTargetIndices  = pinfo.mTargetIndices;\r
+  mRotation       = pinfo.mRotation;\r
+  mParseResult    = pinfo.mParseResult;\r
+  mErrorNo        = pinfo.mErrorNo;\r
+}\r
+\r
+/**\r
+ *  Operator<<\r
+ */\r
+std::ostream &operator<<(std::ostream &os, const QParseInfo &pinfo) {\r
+  os <<   "operator    : " << pinfo.mOperator;\r
+  if (pinfo.mParseResult)\r
+    os << "\nparse result: true";\r
+  else\r
+    os << "\nparse result: false";\r
+  os << "\nerror no.   : " << pinfo.mErrorNo;\r
+  return os;\r
+}\r
diff --git a/compiler/QParseInfo.h b/compiler/QParseInfo.h
new file mode 100644 (file)
index 0000000..947be29
--- /dev/null
@@ -0,0 +1,57 @@
+//----------------------------------------------------------------------------\r
+//  Parse information\r
+//----------------------------------------------------------------------------\r
+#ifndef QPARSEINFO_H\r
+#define QPARSEINFO_H\r
+\r
+#include <iostream>\r
+#include <string>\r
+#include <vector>\r
+\r
+// ---------------------------------------------------------------------------\r
+class QParseInfo {\r
+  friend std::ostream &operator<<(std::ostream &os, const QParseInfo &pinfo);\r
+public:\r
+  static const int er_no_error           = 0;\r
+  static const int er_syntax_error       = 1;\r
+  static const int er_unknown_operation  = 2;\r
+  static const int er_lack_of_arguments  = 3;\r
+  static const int er_too_many_arguments = 4;\r
+  static const int er_invalid_arguments  = 5;\r
+\r
+  QParseInfo(const QParseInfo &pinfo);\r
+  QParseInfo(const int _error);\r
+  QParseInfo(const int _operator,\r
+             const std::vector<int> &_targets,\r
+             const double _rotation = 0,\r
+             const bool _result = true,\r
+             const int _error = 0);\r
+\r
+  ~QParseInfo() {}\r
+\r
+  int                 getOperator(void) const {\r
+    return mOperator;\r
+  }\r
+  const std::vector<int> &getTargetIndices(void) const {\r
+    return mTargetIndices;\r
+  }\r
+  double                 getRotation(void) const {\r
+    return mRotation;\r
+  }\r
+  bool                getParseResult(void) const {\r
+    return mParseResult;\r
+  }\r
+  int                 getErrorNo(void) const {\r
+    return mErrorNo;\r
+  }\r
+private:\r
+  int                 mOperator;\r
+  std::vector<int>    mTargetIndices;\r
+  double                 mRotation;\r
+  bool                mParseResult;\r
+  int                 mErrorNo;\r
+};\r
+\r
+std::ostream &operator<<(std::ostream &os, const QParseInfo &pinfo);\r
+\r
+#endif //QPARSEINFO_H\r
diff --git a/compiler/compiler_main.cpp b/compiler/compiler_main.cpp
new file mode 100644 (file)
index 0000000..d23628c
--- /dev/null
@@ -0,0 +1,38 @@
+/*\r
+ *  Copyright (C) 2002 QCAD project.  All Rights Reserved.\r
+ *\r
+ *  Questions and comments to:\r
+ *       <mailto:jun@bopper.t.u-tokyo.ac.jp>\r
+ *       <http://acolyte.t.u-tokyo.ac.jp/~kaityo/qcaddev/>\r
+ */\r
+\r
+#include <iostream>\r
+#include <fstream>\r
+#include <cstdlib>\r
+\r
+#include "QBits.h"\r
+#include "QCalcManager.h"\r
+#include "QCompiler.h"\r
+#include "QParseInfo.h"\r
+\r
+int main(void) {\r
+//std::ifstream ifs("sample1.mcd", std::ios::in);\r
+  std::ifstream ifs("sample1.mcd", std::ios::in);\r
+  if (!ifs) {\r
+    std::cerr << "Cannot open the source file.\n";\r
+    std::exit(1);\r
+  }\r
+  QBits *qBits = new QBits(7);\r
+  QCalcManager *qCalcManager = new QCalcManager(ifs);\r
+\r
+  std::cout << qBits << "\n";\r
+  qCalcManager->Calc(qBits);\r
+  std::cout << qBits << "\n";\r
+  std::cout << "done." << std::endl;\r
+\r
+  qBits->SaveToFile("sample1.qdt");\r
+\r
+  delete qBits;\r
+  delete qCalcManager;\r
+  ifs.close();\r
+}\r
diff --git a/compiler/makefile b/compiler/makefile
new file mode 100644 (file)
index 0000000..f3dc78b
--- /dev/null
@@ -0,0 +1,89 @@
+# =============================================================================
+#      Makefile for qcompiler
+# =============================================================================
+
+.SUFFIXES: .cpp
+
+all: qcrun qcpp
+
+# Binary file name
+BINNAME=qcrun
+BINNAME2=qcpp
+
+# Normal compiler
+CC=g++
+
+# Where to install
+INSTDIR = ~/bin
+
+# Compile options
+PATH_ROOT = ../calcunits
+PATH_UNITS = ../calcunits
+PATH_LIB = ../qclib
+IFLAGS = -I. -I${PATH_ROOT} -I${PATH_UNITS}
+#CFLAGS = -mno-cygwin -Wall -O4
+CFLAGS = -Wall
+#CFLAGS =  -O2
+LFLAGS = -lm 
+
+# -----------------------------------------------------------------------------
+#      Compiler
+# -----------------------------------------------------------------------------
+QCompiler.o: QCompiler.cpp QCompiler.h QParseInfo.h
+       ${CC} ${IFLAGS} ${CFLAGS} -c QCompiler.cpp -o QCompiler.o
+
+QCompilerCntl.o: QCompilerCntl.cpp QCompilerCntl.h QCompiler.h QParseInfo.h ${PATH_UNITS}/QCalcUnit.h ${QC_UNITS_H}
+       ${CC} ${IFLAGS} ${CFLAGS} -c QCompilerCntl.cpp -o QCompilerCntl.o
+
+QParseInfo.o: QParseInfo.h
+       ${CC} ${IFLAGS} ${CFLAGS} -c QParseInfo.cpp -o QParseInfo.o
+
+QBits.o: ${PATH_ROOT}/QBits.cpp ${PATH_ROOT}/QBits.h
+       ${CC} ${IFLAGS} ${CFLAGS} -c ${PATH_ROOT}/QBits.cpp -o QBits.o
+
+QCalcManager.o: ${PATH_ROOT}/QCalcManager.cpp ${PATH_ROOT}/QCalcManager.h QCompilerCntl.h ${PATH_ROOT}/QBits.h ${PATH_UNITS}/QCalcUnit.h
+       ${CC} ${IFLAGS} ${CFLAGS} -c ${PATH_ROOT}/QCalcManager.cpp -o QCalcManager.o
+
+QCompilerCode.o: QCompilerCode.cpp QCompilerCode.h QCompiler.h QParseInfo.h
+       $(CC) $(IFLAGS) $(CFLAGS) -c QCompilerCode.cpp -o QCompilerCode.o
+
+qcrun.o: qcrun.cpp ${PATH_ROOT}/QBits.h ${PATH_ROOT}/QCalcManager.h
+       ${CC} ${IFLAGS} ${CFLAGS} -c qcrun.cpp -o qcrun.o
+
+qcpp.o: qcpp.cpp QCompilerCode.h QCompiler.h
+       $(CC) $(IFLAGS) $(CFLAGS) -c qcpp.cpp -o qcpp.o
+# -----------------------------------------------------------------------------
+$(BINNAME): qcrun.o QCalcManager.o QCompiler.o QCompilerCntl.o QParseInfo.o ${PATH_LIB}/qclib.a
+       ${CC} ${IFLAGS} -o ${BINNAME} qcrun.o QCalcManager.o QCompiler.o QCompilerCntl.o QParseInfo.o ${CFLAGS} ${LFLAGS} ${PATH_LIB}/qclib.a
+
+$(BINNAME2): qcpp.o QCompilerCode.o QCompiler.o QParseInfo.o
+       $(CC) $(IFLAGS) -o $(BINNAME2) qcpp.o QCompilerCode.o QCompiler.o QParseInfo.o $(CFLAGS) $(LFLAGS)
+
+# -----------------------------------------------------------------------------
+#      Other functions
+# -----------------------------------------------------------------------------
+clean:
+       -rm -f *.o ${BINNAME} $(BINNAME2)
+       -rm -f ${BINNAME}.exe $(BINNAME2).exe
+       -rm -f *.~* *.obj
+
+# -----------------------------------------------------------------------------
+install: qcompiler
+       @if [ -d ${INSTDIR} ]; \
+       then \
+               cp ${OPT_BINNAME} ${INSTDIR}; \
+               chmod 711 ${INSTDIR}/${OPT_BINNAME}; \
+               echo "Installed in ${INSTDIR}"; \
+       else \
+               echo "Sorry, ${INSTDIR} does not exist."; \
+       fi
+
+# -----------------------------------------------------------------------------
+uninstall:
+       @if [ -e ${INSTDIR}/${OPT_BINNAME} ]; \
+       then \
+               -rm ${INSTDIR}/${OPT_BINNAME}; \
+               echo "unnstalled successfully."; \
+       else \
+               echo "Sorry, ${INSTDIR}/${OPT_BINNAME} does not exist."; \
+       fi
diff --git a/compiler/makefile_bcc b/compiler/makefile_bcc
new file mode 100644 (file)
index 0000000..86dfbad
--- /dev/null
@@ -0,0 +1,97 @@
+# =============================================================================\r
+#      Makefile for bcc32\r
+# =============================================================================\r
+\r
+all: qcompiler\r
+\r
+# Binary file name\r
+BINNAME = qcompiler_test.exe\r
+\r
+# Normal compiler\r
+#CC = c++\r
+CC = bcc32\r
+\r
+# Where to install\r
+INSTDIR = ~/bin\r
+\r
+# Compile options\r
+PATH_ROOT = ..\r
+PATH_UNITS = ../calcunits\r
+IFLAGS = -I. -I${PATH_ROOT} -I${PATH_UNITS}\r
+#CFLAGS = -Wall -ansi -O2\r
+LFLAGS = -lm\r
+\r
+# -----------------------------------------------------------------------------\r
+#      CalcUnits\r
+# -----------------------------------------------------------------------------\r
+QC_UNITS_H = ${PATH_UNITS}/QC_not.h ${PATH_UNITS}/QC_hadamard.h ${PATH_UNITS}/QC_cnot.h ${PATH_UNITS}/QC_crot.h\r
+QC_UNITS_O = QC_not.obj QC_hadamard.obj QC_cnot.obj QC_crot.obj\r
+\r
+QCalcUnit.obj: ${PATH_UNITS}/QCalcUnit.cpp ${PATH_UNITS}/QCalcUnit.h\r
+       ${CC} ${IFLAGS} ${CFLAGS} -c ${PATH_UNITS}/QCalcUnit.cpp -o QCalcUnit.obj\r
+\r
+QC_not.obj: ${PATH_UNITS}/QC_not.cpp ${PATH_UNITS}/QC_not.h ${PATH_UNITS}/QCalcUnit.h ${PATH_ROOT}/QBits.h\r
+       ${CC} ${IFLAGS} ${CFLAGS} -c ${PATH_UNITS}/QC_not.cpp -o QC_not.obj\r
+\r
+QC_cnot.obj: ${PATH_UNITS}/QC_cnot.cpp ${PATH_UNITS}/QC_cnot.h ${PATH_UNITS}/QCalcUnit.h ${PATH_ROOT}/QBits.h\r
+       ${CC} ${IFLAGS} ${CFLAGS} -c ${PATH_UNITS}/QC_cnot.cpp -o QC_cnot.obj\r
+\r
+QC_crot.obj: ${PATH_UNITS}/QC_crot.cpp ${PATH_UNITS}/QC_crot.h ${PATH_UNITS}/QCalcUnit.h ${PATH_ROOT}/QBits.h\r
+       ${CC} ${IFLAGS} ${CFLAGS} -c ${PATH_UNITS}/QC_crot.cpp -o QC_crot.obj\r
+\r
+QC_hadamard.obj: ${PATH_UNITS}/QC_hadamard.cpp ${PATH_UNITS}/QC_hadamard.h ${PATH_UNITS}/QCalcUnit.h ${PATH_ROOT}/QBits.h\r
+       ${CC} ${IFLAGS} ${CFLAGS} -c ${PATH_UNITS}/QC_hadamard.cpp -o QC_hadamard.obj\r
+\r
+# -----------------------------------------------------------------------------\r
+#      Compiler\r
+# -----------------------------------------------------------------------------\r
+QCompiler.obj: QCompiler.cpp QCompiler.h QParseInfo.h\r
+       ${CC} ${IFLAGS} ${CFLAGS} -c QCompiler.cpp -o QCompiler.obj\r
+\r
+QCompilerCntl.obj: QCompilerCntl.cpp QCompilerCntl.h QCompiler.h QParseInfo.h ${PATH_UNITS}/QCalcUnit.h ${QC_UNITS_H}\r
+       ${CC} ${IFLAGS} ${CFLAGS} -c QCompilerCntl.cpp -o QCompilerCntl.obj\r
+\r
+QParseInfo.obj: QParseInfo.h\r
+       ${CC} ${IFLAGS} ${CFLAGS} -c QParseInfo.cpp -o QParseInfo.obj\r
+\r
+QBits.obj: ${PATH_ROOT}/QBits.cpp ${PATH_ROOT}/QBits.h\r
+       ${CC} ${IFLAGS} ${CFLAGS} -c ${PATH_ROOT}/QBits.cpp -o QBits.obj\r
+\r
+QCalcManager.obj: ${PATH_ROOT}/QCalcManager.cpp ${PATH_ROOT}/QCalcManager.h QCompilerCntl.h ${PATH_ROOT}/QBits.h ${PATH_UNITS}/QCalcUnit.h\r
+       ${CC} ${IFLAGS} ${CFLAGS} -c ${PATH_ROOT}/QCalcManager.cpp -o QCalcManager.obj\r
+\r
+compiler_main.obj: compiler_main.cpp ${PATH_ROOT}/QBits.h ${PATH_ROOT}/QCalcManager.h\r
+       ${CC} ${IFLAGS} ${CFLAGS} -c compiler_main.cpp -o compiler_main.obj\r
+\r
+# -----------------------------------------------------------------------------\r
+qcompiler: compiler_main.obj QBits.obj QCalcManager.obj QCompiler.obj QCompilerCntl.obj QParseInfo.obj QCalcUnit.obj ${QC_UNITS_O}\r
+       ${CC} ${IFLAGS} -o ${BINNAME} compiler_main.obj QBits.obj QCalcManager.obj QCompiler.obj QCompilerCntl.obj QParseInfo.obj QCalcUnit.obj ${QC_UNITS_O} ${CFLAGS} ${LFLAGS}\r
+\r
+\r
+# -----------------------------------------------------------------------------\r
+#      Other functions\r
+# -----------------------------------------------------------------------------\r
+clean:\r
+       -rm -f *.obj ${BINNAME}\r
+\r
+# -----------------------------------------------------------------------------\r
+install: qcompiler\r
+       @if [ -d ${INSTDIR} ]; \\r
+       then \\r
+               cp ${OPT_BINNAME} ${INSTDIR}; \\r
+               chmod 711 ${INSTDIR}/${OPT_BINNAME}; \\r
+               echo "Installed in ${INSTDIR}"; \\r
+       else \\r
+               echo "Sorry, ${INSTDIR} does not exist."; \\r
+       fi\r
+\r
+# -----------------------------------------------------------------------------\r
+uninstall:\r
+       @if [ -e ${INSTDIR}/${OPT_BINNAME} ]; \\r
+       then \\r
+               -rm ${INSTDIR}/${OPT_BINNAME}; \\r
+               echo "unnstalled successfully."; \\r
+       else \\r
+               echo "Sorry, ${INSTDIR}/${OPT_BINNAME} does not exist."; \\r
+       fi\r
+\r
diff --git a/compiler/man/man1/qcc.1 b/compiler/man/man1/qcc.1
new file mode 100644 (file)
index 0000000..e17abba
--- /dev/null
@@ -0,0 +1,100 @@
+.TH QCC
+
+.SH NAME
+qcc \- Quantum Circuits Compiler
+      version 1.0
+
+.SH SYNOPSIS
+qcc [ \-c |\-\-help|\-h|\-v|\-V ] 
+    [ \-C file.cpp ]
+    [ \-o file.cpp/file.exe ]
+    source.mcd
+.PP
+All options are listed here.
+Notice that the options \-c and \-C cannot be used at the same time.
+If done, \fIqcc\fP may not work as you intended.
+
+.SH DESCRIPTION
+
+.PP
+\fIqcc\fP is an application that compile an mcd code into an
+executable or a c++ code.
+.PP
+When you invoke \fIqcc\fP, it normally does compilation and linking.
+The some options allow you to stop this process at an intermediate stage.
+For example, the \-c option says not to run the linker. Then the output
+consists of object files output by the mcd compiler; \fIqcpp\fP.
+
+.SH OPTIONS
+Option Details
+.TP
+\-c
+Compile the source files into c++ code, and stop in that stage.
+The next compiling and linking stage simply is not done.
+The ultimate output is in the form of a c++ code for each source file.
+.IP
+By default, the output file name for a source file is made by replacing the
+suffix .mcd with .cpp
+
+.TP
+\-\-help
+Print (on the standard output) a description of the command line options
+understood by qcc. 
+
+.TP
+\-h
+Identical with \-\-help.
+
+.TP
+\-v
+Print (on the standard error output) the commands executed to run the stage of
+compilation.
+
+.TP
+\-V
+Print (on the standard output) the version of this software.
+
+.TP
+\-C \fIfile\fP
+Place output c++ code in file \fIfile\fP.
+This option is useful when you want to obtain both the executable and the
+c++ code simultaneously.
+It is effective only when \-c option is \fBNOT\fP specified.
+.IP
+If \-c option, \-C option and \-o option are specified at the same time,
+the \-C option will be ignored.
+
+.TP
+\-o \fIfile\fP
+Place output in file \fIfile\fP.
+This applies regardless to whatever sort of output is being produced, whether
+it be an executable file or a c++ code.
+Therefore, this option conflicts with \-C option.
+.IP
+If \-o is not specified, the default is put an executable file in \fIa.out\fP,
+the c++ code for \fIsource\fP.mcd in \fIsource\fP.cpp.
+
+.SH BUGS
+For reporting bugs, please mail to
+    <\fBjun@bopper.t.u-tokyo.ac.jp\fP>
+, or
+    <\fBkaityo@acolyte.t.u-tokyo.ac.jp\fP>
+
+.SH SEE ALSO
+\fIqcpp\fP(1), \fIqcrun\fP(1), \fIQCAD\fP(?)
+
+.SH AUTHOR
+This document is written by J. Yamazaki.
+
+.SH COPYRIGHT
+Copyright (c) 2002, 2003 QCAD project at the University of Tokyo,
+Department of Applied Physics.
+.PP
+Permission is granted to distribute this document only if you've not changed
+the contents of the package.
+I hope this software will be distributed and/or modified under the term of
+GNU Free Documentation License in the future, but not yet.
+Please keep it in mind.
+For more details, please see QCAD web site.
+.PP
+<http://acolyte.t.u-tokyo.ac.jp/~kaityo/qcad/>
diff --git a/compiler/man/man1/qcpp.1 b/compiler/man/man1/qcpp.1
new file mode 100644 (file)
index 0000000..c79a747
--- /dev/null
@@ -0,0 +1,61 @@
+.TH QCPP\r
+\r
+.SH NAME\r
+qcpp \- One of the utilities which is invoked by \fIqcc\fP.\r
+\r
+.SH SYNOPSIS\r
+.PP\r
+qcpp [ \-hvV ] [ \-o \fIoutput.cpp\fP ] \fIsource\fP.mcd\r
+\r
+.SH DESCRIPTION\r
+.PP\r
+\fIqcpp\fP is a compiler for the mcd code which is generated by\r
+\fIQCAD\fP.\r
+.PP\r
+When you invoke \fIqcpp\fP with no option, it normally reads the input mcd\r
+code, parses and print the result of compilation on the standard output.\r
+\r
+.SH OPTIONS\r
+Option Details\r
+.TP\r
+\-h\r
+Print (on the standard output) a description of the command line options\r
+understood by qcpp.\r
+\r
+.TP\r
+\-v\r
+Print (on the standard error output) the details of the compilation,\r
+which include the input file, the output file and the running states.\r
+\r
+.TP\r
+\-V\r
+Print (on the standard output) the version of this software.\r
+\r
+.TP\r
+\-o \fIfile\fP\r
+Place output the result of the compilation in file \fIfile\fP.\r
+\r
+.SH BUGS\r
+For reporting bugs, please mail to\r
+    <\fBjun@bopper.t.u-tokyo.ac.jp\fP>\r
+, or\r
+    <\fBkaityo@acolyte.t.u-tokyo.ac.jp\fP>\r
+\r
+.SH SEE ALSO\r
+\fIqcpp\fP(1), \fIqcrun\fP(1), \fIQCAD\fP\r
+\r
+.SH AUTHOR\r
+This document is written by J. Yamazaki.\r
+\r
+.SH COPYRIGHT\r
+Copyright (c) 2002, 2003 QCAD project at the University of Tokyo,\r
+Department of Applied Physics.\r
+.PP\r
+Permission is granted to distribute this document only if you've not changed\r
+the contents of the package.\r
+I hope this software will be distributed and/or modified under the term of\r
+GNU Free Documentation License in the future, but not yet.\r
+Please keep it in mind.\r
+For more details, please see QCAD web site.\r
+.PP\r
+<http://acolyte.t.u-tokyo.ac.jp/~kaityo/qcad/>\r
diff --git a/compiler/man/man1/qcrun.1 b/compiler/man/man1/qcrun.1
new file mode 100644 (file)
index 0000000..110d2ae
--- /dev/null
@@ -0,0 +1,67 @@
+.TH QCRUN\r
+\r
+.SH NAME\r
+qcrun \- Quantum Circuit Runner\r
+        An interpreter for mcd code of QCAD\r
+\r
+.SH SYNOPSIS\r
+.PP\r
+qcrun [ \-hvV ] [ \-o \fIoutput.qdt\fP ] \fIsource\fP.mcd\r
+\r
+.SH DESCRIPTION\r
+.PP\r
+\fIqcrun\fP is an interpreter for the mcd code which is generated by\r
+\fIQCAD\fP.\r
+.PP\r
+When you invoke \fIqcrun\fP with no option, it normally reads the input mcd\r
+code, calculates and stores the result in the file whose name is specified\r
+simply by replacing the suffix .mcd with .qdt, the general format of qubits\r
+which is used in \fIQCAD\fP.\r
+\r
+.SH OPTIONS\r
+Option Details\r
+.TP\r
+\-h\r
+Print (on the standard output) a description of the command line options\r
+understood by qcrun.\r
+\r
+.TP\r
+\-v\r
+Print (on the standard error output) the details of the interpretation,\r
+which include the input file, the output file and the running states.\r
+\r
+.TP\r
+\-V\r
+Print (on the standard output) the version of this software.\r
+\r
+.TP\r
+\-o \fIfile\fP\r
+Place output the result of the calculation in file \fIfile\fP.\r
+.IP\r
+By default, \fIfile\fP is specified simply by replacing\r
+the suffix .mcd with .qdt.\r
+\r
+.SH BUGS\r
+For reporting bugs, please mail to\r
+    <\fBjun@bopper.t.u-tokyo.ac.jp\fP>\r
+, or\r
+    <\fBkaityo@acolyte.t.u-tokyo.ac.jp\fP>\r
+\r
+.SH SEE ALSO\r
+\fIqcpp\fP(1), \fIqcrun\fP(1), \fIQCAD\fP\r
+\r
+.SH AUTHOR\r
+This document is written by J. Yamazaki.\r
+\r
+.SH COPYRIGHT\r
+Copyright (c) 2002, 2003 QCAD project at the University of Tokyo,\r
+Department of Applied Physics.\r
+.PP\r
+Permission is granted to distribute this document only if you've not changed\r
+the contents of the package.\r
+I hope this software will be distributed and/or modified under the term of\r
+GNU Free Documentation License in the future, but not yet.\r
+Please keep it in mind.\r
+For more details, please see QCAD web site.\r
+.PP\r
+<http://acolyte.t.u-tokyo.ac.jp/~kaityo/qcad/>\r
diff --git a/compiler/qcc b/compiler/qcc
new file mode 100644 (file)
index 0000000..4c37bae
--- /dev/null
@@ -0,0 +1,242 @@
+#!/bin/sh\r
+\r
+###############################################################################\r
+#                                                                             #\r
+#   qcc - Quantum Circuit Compiler for Unix                                   #\r
+#   J. Yamazaki, M. Suzuki and H. Watanabe                                    #\r
+#   Copyright (C) 2003 QCAD project, all rights reserved.                     #\r
+#                                                                             #\r
+###############################################################################\r
+\r
+\r
+###############################################################################\r
+# Global valuables\r
+###############################################################################\r
+# ocppfile\r
+# ofile\r
+# ifile\r
+# qcpp_args\r
+# gcc_args\r
+\r
+er_str0="Try 'qcc --help' for more information."\r
+er_str1="No output file."\r
+er_str2=" is unexpected option."\r
+er_str3="'-o' option can be used only once."\r
+er_str4="Too many input files."\r
+er_str5="No input file."\r
+er_str6="File not found."\r
+er_str7="'-C' option can be used only once."\r
+\r
+version_str1="qcc version 0.2"\r
+version_str2="Copyright (C) 2003 QCAD project."\r
+\r
+opt_stop=0\r
+opt_create=0\r
+opt_input=0\r
+opt_output=0\r
+opt_verbose=0\r
+\r
+inst_dir=../calcunits\r
+\r
+###############################################################################\r
+print_usage()\r
+{\r
+       echo "Usage: qcc [options] file"\r
+       echo "Options:"\r
+       echo "  --help, -h ... Display this information"\r
+       echo "  -c         ... Compile into c++, but do not link"\r
+       echo "  -C \e[36mfile\e[00m    ... Create intermediate c++ file as \e[36mfile\e[00m"\r
+       echo "                 (is effective only when '-c' is not selected)"\r
+       echo "  -o \e[36mfile\e[00m    ... Place the output into \e[36mfile\e[00m"\r
+       echo "                 (is effective for both c++ file and executables)"\r
+       echo "  -v         ... Display the programs invoked by the compiler"\r
+       echo "  -V         ... Display qcc version number"\r
+       echo "Examples:"\r
+       echo "  qcc -c sample.mcd -o sample.cpp           OK"\r
+       echo "  qcc sample.mcd -o a.out                   OK"\r
+       echo "  qcc sample.mcd -C sample.cpp -o a.out     OK"\r
+       echo "  qcc -c sample.mcd -C sample.cpp -o a.out  \e[31;01mERROR!\e[00m"\r
+       echo "  \e[33mIn the last one, '-C' conflicts with '-o',"\r
+       echo "  then create a.out as c++ file.\e[00m"\r
+}\r
+\r
+###############################################################################\r
+option_create()\r
+{\r
+       if [ $opt_create -eq 0 ]; then\r
+               if [ $1 ]; then\r
+                       ocppfile=$1\r
+                       opt_create=1\r
+               else\r
+                       echo $er_str1\r
+                       exit 1\r
+               fi\r
+       else\r
+               echo $er_str7\r
+               exit 1\r
+       fi\r
+}\r
+\r
+###############################################################################\r
+option_o()\r
+{\r
+       if [ $opt_output -eq 0 ]; then\r
+               if [ $1 ]; then\r
+                       ofile=$1\r
+                       opt_output=1\r
+               else\r
+                       echo $er_str1\r
+                       exit 1\r
+               fi\r
+       else\r
+               echo $er_str3\r
+               exit 1\r
+       fi\r
+}\r
+\r
+###############################################################################\r
+###############################################################################\r
+###############################################################################\r
+###############################################################################\r
+# Analyze arguments...\r
+\r
+if [ $1 ]; then\r
+       :\r
+else\r
+       echo\r
+       echo $version_str2\r
+       echo $version_str1\r
+       echo\r
+       print_usage\r
+       echo\r
+       exit 0\r
+fi\r
+\r
+while [ $1 ]\r
+do\r
+       case $1 in\r
+       --help | -h)\r
+               echo\r
+               print_usage\r
+               echo\r
+               exit 0\r
+               ;;\r
+       -c)\r
+               opt_stop=1\r
+               ;;\r
+       -C)\r
+               shift\r
+               option_create $1\r
+               opt_create=1\r
+               ;;\r
+       -o)\r
+               shift\r
+               option_o $1\r
+               ;;\r
+       -v)\r
+               opt_verbose=1\r
+               ;;\r
+       -V)\r
+               echo\r
+               echo $version_str2\r
+               echo $version_str1\r
+               echo\r
+               exit 0\r
+               ;;\r
+       *)\r
+               if [ $opt_input -eq 0 ]; then\r
+                       ifile=$1\r
+                       opt_input=1\r
+               else\r
+                       echo "$er_str4   '$1'"\r
+                       exit 1\r
+               fi\r
+               ;;\r
+       esac\r
+\r
+       if [ $1 ]; then\r
+               shift\r
+       fi\r
+done\r
+\r
+###############################################################################\r
+# Check arguments...\r
+\r
+if [ $opt_input -eq 0 ]; then\r
+       echo $er_str5\r
+       exit 1\r
+fi\r
+\r
+if !([ -r $ifile ]); then\r
+       echo $er_str6\r
+       exit 1\r
+fi\r
+\r
+###############################################################################\r
+# Create qcpp args\r
+\r
+qcpp_args=""\r
+gcc_args="-I../qclib -I$inst_dir"\r
+\r
+#if [ $opt_verbose -eq 1 ]; then\r
+#      qcpp_args="-v"\r
+#fi\r
+\r
+qcpp_args="$qcpp_args $ifile"\r
+\r
+if [ $opt_stop -eq 1 ]; then\r
+       if [ $opt_output -eq 1 ]; then\r
+               qcpp_args="$qcpp_args -o $ofile"\r
+       fi\r
+else\r
+       if [ $opt_create -eq 0 ]; then\r
+               ocppfile="qcctmp.cpp"\r
+       fi\r
+       qcpp_args="$qcpp_args -o $ocppfile"\r
+#TODO:\r
+       gcc_args="$ocppfile $gcc_args ../qclib/qclib.a -lm"\r
+       if [ $opt_output -eq 1 ]; then\r
+               gcc_args="$gcc_args -o $ofile"\r
+       fi\r
+fi\r
+\r
+###############################################################################\r
+# For debug\r
+#echo "qcpp_args   = $qcpp_args"\r
+#echo "gcc_args    = $gcc_args"\r
+#echo "opt_stop    = $opt_stop"\r
+#echo "opt_create  = $opt_create"\r
+#echo "opt_verbose = $opt_verbose"\r
+#echo "opt_input   = $opt_input"\r
+#echo "opt_output  = $opt_output"\r
+#echo "ocppfile    = $ocppfile"\r
+#echo "ofile       = $ofile"\r
+#echo "ifile       = $ifile"\r
+\r
+###############################################################################\r
+# Compile phase...\r
+\r
+if [ $opt_verbose -eq 1 ]; then\r
+       echo "qcpp $qcpp_args"\r
+fi\r
+if !(qcpp $qcpp_args); then\r
+       exit 1\r
+fi\r
+\r
+if [ $opt_stop -eq 1 ]; then\r
+       exit 0\r
+fi\r
+\r
+###############################################################################\r
+\r
+if [ $opt_verbose -eq 1 ]; then\r
+       echo g++ $gcc_args\r
+fi\r
+\r
+g++ $gcc_args\r
+\r
+if [ $opt_create -eq 0 ] && [ -e $ocppfile ]; then\r
+       rm -f $ocppfile\r
+fi\r
+\r
+exit 0\r
diff --git a/compiler/qcpp.cpp b/compiler/qcpp.cpp
new file mode 100644 (file)
index 0000000..84867ae
--- /dev/null
@@ -0,0 +1,270 @@
+//----------------------------------------------------------------------------\r
+//  qcpp.cpp\r
+//  Interpreter for ntermediate code\r
+//  $Date: 2003/02/20 00:24:16 $\r
+//  $Revision: 1.3 $\r
+//----------------------------------------------------------------------------\r
+#include <iostream>\r
+#include <iomanip>\r
+#include <fstream>\r
+#include <cstdlib>\r
+#include <vector>\r
+#include <string>\r
+\r
+#include "QCompilerCode.h"\r
+\r
+typedef unsigned int                Appoptions;\r
+\r
+const char * const  app_name        = "qcpp";\r
+const char * const  app_version     = "1.0";\r
+const char * const  app_extension   = ".cpp";\r
+\r
+const Appoptions    opt_version     = 1;\r
+const Appoptions    opt_help        = 1 << 1;\r
+const Appoptions    opt_verbose     = 1 << 2;\r
+const Appoptions    opt_output      = 1 << 3;\r
+const Appoptions    opt_input       = 1 << 4;\r
+\r
+//----------------------------------------------------------------------------\r
+//  Function prototypes\r
+//----------------------------------------------------------------------------\r
+inline bool isSet(const Appoptions &o1, const Appoptions &o2) {\r
+  return (o2 == (o1 & o2));\r
+}\r
+\r
+Appoptions  checkOption(const char * inOptions);\r
+void        forceQuit(void);\r
+void        printUsage(void);\r
+void        printVersion(void);\r
+void        errorAndQuit(const char * const inMessage);\r
+std::string setOutputFilename(const std::string &inString,\r
+                              const char * const inExt = app_extension);\r
+\r
+//----------------------------------------------------------------------------\r
+/**\r
+ *  Main\r
+ */\r
+int main(int argc, char **argv) {\r
+  Appoptions      parameters_ready    = 0;\r
+  QCompilerCode   *qCCode             = NULL;\r
+\r
+  std::string               ofilename = "";\r
+  std::string               ifilename = "";\r
+  std::vector<std::string>  args;\r
+\r
+  if (argc <= 1) {\r
+    printVersion();\r
+    printUsage();\r
+    std::exit(0);\r
+  }\r
+\r
+  for (int i = 0; i < argc; i++) {\r
+    std::string tmpstr = argv[i];\r
+    args.push_back(tmpstr);\r
+  }\r
+\r
+  unsigned int vec_size = args.size();\r
+  unsigned int arg_at   = 1;\r
+\r
+  while (arg_at < vec_size) {\r
+    if ('-' == args[arg_at][0] && args[arg_at].length() > 1) {\r
+      Appoptions tmpoptions = checkOption(args[arg_at].c_str());\r
+\r
+      //_____ HELP _____\r
+      if (isSet(tmpoptions, opt_help)) {\r
+        if (isSet(parameters_ready, opt_help)) {\r
+          errorAndQuit("-h option can be used only once.");\r
+        } else {\r
+          parameters_ready |= opt_help;\r
+        }\r
+      }\r
+\r
+      //_____ VERBOSE _____\r
+      if (isSet(tmpoptions, opt_verbose)) {\r
+        if (isSet(parameters_ready, opt_verbose)) {\r
+          errorAndQuit("-v option can be used only once.");\r
+        } else {\r
+          parameters_ready |= opt_verbose;\r
+        }\r
+      }\r
+\r
+      //_____ VERSION _____\r
+      if (isSet(tmpoptions, opt_version)) {\r
+        if (isSet(parameters_ready, opt_version)) {\r
+          errorAndQuit("-V option can be used only once.");\r
+        } else {\r
+          parameters_ready |= opt_version;\r
+        }\r
+      }\r
+\r
+      //_____ OUTPUT _____\r
+      if (isSet(tmpoptions, opt_output)) {\r
+        if (isSet(parameters_ready, opt_output)) {\r
+          errorAndQuit("-o option can be used only once.");\r
+        }\r
+\r
+        if (arg_at < vec_size - 1) {\r
+          ofilename         = args[++arg_at];\r
+          parameters_ready |= opt_output;\r
+        } else {\r
+          errorAndQuit("too few parameters.");\r
+        }\r
+      }\r
+      arg_at++;\r
+      continue;\r
+    }\r
+\r
+    if (isSet(parameters_ready, opt_input)) {\r
+      errorAndQuit("too many input file.");\r
+    } else {\r
+      ifilename = args[arg_at];\r
+      parameters_ready |= opt_input;\r
+    }\r
+    arg_at++;\r
+  }\r
+\r
+  //_____ VERSION _____\r
+  if (isSet(parameters_ready, opt_version)) printVersion();\r
+\r
+  //_____ HELP ________\r
+  if (isSet(parameters_ready, opt_help))    printUsage();\r
+\r
+  //_____ OUTPUT ______\r
+  if (isSet(parameters_ready, opt_input)) {\r
+    if (false == isSet(parameters_ready, opt_output)) {\r
+      ofilename = "none";\r
+    }\r
+\r
+    std::ifstream ifs(ifilename.c_str(), std::ios::in);\r
+    if (!ifs) {\r
+      std::cerr << "Cannot open the input file.\n";\r
+      forceQuit();\r
+    }\r
+\r
+    if (isSet(parameters_ready, opt_verbose)) {\r
+      std::cerr << "Input  file: " << ifilename << "\n"\r
+                << "Output file: " << ofilename << "\n";\r
+    }\r
+\r
+    try {\r
+      qCCode      = new QCompilerCode(ifs, setOutputFilename(ifilename, ".qdt").c_str());\r
+    } catch (const std::bad_alloc ex) {\r
+      std::cerr << "Failed in memory allocation.\n";\r
+      forceQuit();\r
+    }\r
+\r
+    if (true == qCCode->Compile()) {\r
+      if (isSet(parameters_ready, opt_output)) {\r
+        std::ofstream ofs(ofilename.c_str(), std::ios::out);\r
+        qCCode->SaveToStream(ofs);\r
+        ofs.close();\r
+      } else {\r
+        qCCode->SaveToStream(std::cout);\r
+      }\r
+    }\r
+\r
+    delete qCCode;\r
+\r
+    ifs.close();\r
+\r
+    if (isSet(parameters_ready, opt_verbose)) {\r
+      std::cerr << "qcpp: done." << std::endl;\r
+    }\r
+  }\r
+\r
+  return 0;\r
+}\r
+\r
+//----------------------------------------------------------------------------\r
+/**\r
+ *  Check options\r
+ */\r
+Appoptions checkOption(const char * inOptions) {\r
+  Appoptions retVal = 0;\r
+  inOptions++;\r
+  while ('\0' != *inOptions) {\r
+    switch (*inOptions) {\r
+    case 'h':\r
+      retVal |= opt_help;\r
+      break;\r
+    case 'o':\r
+      retVal |= opt_output;\r
+      break;\r
+    case 'v':\r
+      retVal |= opt_verbose;\r
+      break;\r
+    case 'V':\r
+      retVal |= opt_version;\r
+      break;\r
+    default:\r
+      errorAndQuit("there are some invalid options.");\r
+      break;\r
+    }\r
+    inOptions++;\r
+  }\r
+  return retVal;\r
+}\r
+\r
+//----------------------------------------------------------------------------\r
+/**\r
+ *  Force quit\r
+ */\r
+void forceQuit(void) {\r
+  std::cerr << "Quit forced.\n";\r
+  std::exit(1);\r
+}\r
+\r
+//----------------------------------------------------------------------------\r
+/**\r
+ *  Print usages\r
+ */\r
+void printUsage(void) {\r
+  std::cout << "Usage: " << app_name\r
+            << " [-hvV] [-o output_file] input_file.mcd\n\n"\r
+            << "    -h  show this help\n"\r
+            << "    -v  verbose mode\n"\r
+            << "    -V  show version\n\n"\r
+            << std::flush;\r
+}\r
+\r
+//----------------------------------------------------------------------------\r
+/**\r
+ *  Print version\r
+ */\r
+void printVersion(void) {\r
+  std::cout << "\nCopyright (C) 2002-2003 QCAD project\n"\r
+            << app_name << " version " << app_version << "\n\n"\r
+            << std::flush;\r
+}\r
+\r
+//----------------------------------------------------------------------------\r
+/**\r
+ *  Show message and quit\r
+ */\r
+void errorAndQuit(const char * const inMessage) {\r
+  std::cerr << "Error: " << inMessage << "\n\n";\r
+  printUsage();\r
+  forceQuit();\r
+}\r
+\r
+//----------------------------------------------------------------------------\r
+/**\r
+ *  Set output filename\r
+ */\r
+std::string setOutputFilename(const std::string &inString,\r
+                              const char * const inExt) {\r
+  std::string retString = "";\r
+\r
+  unsigned int posdot = inString.rfind(".", inString.length() - 1);\r
+\r
+  if (posdot == std::string::npos) {\r
+    retString = inString;\r
+  } else {\r
+    retString.assign(inString, 0, posdot);\r
+  }\r
+\r
+  retString += inExt;\r
+\r
+  return retString;\r
+}\r
+\r
diff --git a/compiler/qcrun.cpp b/compiler/qcrun.cpp
new file mode 100644 (file)
index 0000000..5898a85
--- /dev/null
@@ -0,0 +1,313 @@
+//----------------------------------------------------------------------------\r
+//  qcrun.cpp\r
+//  Interpreter for ntermediate code\r
+//  $Date: 2003/02/20 00:24:16 $\r
+//  $Revision: 1.8 $\r
+//----------------------------------------------------------------------------\r
+#include <iostream>\r
+#include <iomanip>\r
+#include <fstream>\r
+#include <cstdlib>\r
+#include <vector>\r
+#include <string>\r
+\r
+#include "QBits.h"\r
+#include "QCompilerCntl.h"\r
+#include "QCalcUnit.h"\r
+\r
+typedef unsigned int                Appoptions;\r
+typedef std::vector<QCalcUnit *>    QCalcUnits;\r
+\r
+const char * const  app_name        = "qcrun";\r
+const char * const  app_version     = "1.0";\r
+\r
+const Appoptions    opt_version     = 1;\r
+const Appoptions    opt_help        = 1 << 1;\r
+const Appoptions    opt_verbose     = 1 << 2;\r
+const Appoptions    opt_output      = 1 << 3;\r
+const Appoptions    opt_input       = 1 << 4;\r
+\r
+//----------------------------------------------------------------------------\r
+//  Function prototypes\r
+//----------------------------------------------------------------------------\r
+inline bool isSet(const Appoptions &o1, const Appoptions &o2) {\r
+  return (o2 == (o1 & o2));\r
+}\r
+\r
+Appoptions  checkOption(const char * inOptions);\r
+void        compile(QCompilerCntl * const , QCalcUnits * const);\r
+void        forceQuit(void);\r
+void        printUsage(void);\r
+void        printVersion(void);\r
+void        errorAndQuit(const char * const inMessage);\r
+std::string setOutputFilename(const std::string &inString);\r
+\r
+//----------------------------------------------------------------------------\r
+/**\r
+ *  Main\r
+ */\r
+int main(int argc, char **argv) {\r
+  Appoptions      parameters_ready    = 0;\r
+  QBits           *qBits              = NULL;\r
+  QCompilerCntl   *qCCntl             = NULL;\r
+  QCalcUnits      *qCalcUnits         = NULL;\r
+\r
+  std::string               ofilename = "";\r
+  std::string               ifilename = "";\r
+  std::vector<std::string>  args;\r
+\r
+  if (argc <= 1) {\r
+    printVersion();\r
+    printUsage();\r
+    std::exit(0);\r
+  }\r
+\r
+  for (int i = 0; i < argc; i++) {\r
+    std::string tmpstr = argv[i];\r
+    args.push_back(tmpstr);\r
+  }\r
+\r
+  int vec_size = args.size();\r
+  int arg_at   = 1;\r
+\r
+  while (arg_at < vec_size) {\r
+    if ('-' == args[arg_at][0] && args[arg_at].length() > 1) {\r
+      Appoptions tmpoptions = checkOption(args[arg_at].c_str());\r
+\r
+      //_____ HELP _____\r
+      if (isSet(tmpoptions, opt_help)) {\r
+        if (isSet(parameters_ready, opt_help)) {\r
+          errorAndQuit("-h option can be used only once.");\r
+        } else {\r
+          parameters_ready |= opt_help;\r
+        }\r
+      }\r
+\r
+      //_____ VERBOSE _____\r
+      if (isSet(tmpoptions, opt_verbose)) {\r
+        if (isSet(parameters_ready, opt_verbose)) {\r
+          errorAndQuit("-v option can be used only once.");\r
+        } else {\r
+          parameters_ready |= opt_verbose;\r
+        }\r
+      }\r
+\r
+      //_____ VERSION _____\r
+      if (isSet(tmpoptions, opt_version)) {\r
+        if (isSet(parameters_ready, opt_version)) {\r
+          errorAndQuit("-V option can be used only once.");\r
+        } else {\r
+          parameters_ready |= opt_version;\r
+        }\r
+      }\r
+\r
+      //_____ OUTPUT _____\r
+      if (isSet(tmpoptions, opt_output)) {\r
+        if (isSet(parameters_ready, opt_output)) {\r
+          errorAndQuit("-o option can be used only once.");\r
+        }\r
+\r
+        if (arg_at < vec_size - 1) {\r
+          ofilename         = args[++arg_at];\r
+          parameters_ready |= opt_output;\r
+        } else {\r
+          errorAndQuit("too few parameters.");\r
+        }\r
+      }\r
+      arg_at++;\r
+      continue;\r
+    }\r
+\r
+    if (isSet(parameters_ready, opt_input)) {\r
+      errorAndQuit("too many input file.");\r
+    } else {\r
+      ifilename = args[arg_at];\r
+      parameters_ready |= opt_input;\r
+    }\r
+    arg_at++;\r
+  }\r
+\r
+  //_____ VERSION _____\r
+  if (isSet(parameters_ready, opt_version)) printVersion();\r
+\r
+  //_____ HELP ________\r
+  if (isSet(parameters_ready, opt_help))    printUsage();\r
+\r
+  //_____ OUTPUT ______\r
+  if (isSet(parameters_ready, opt_input)) {\r
+    if (false == isSet(parameters_ready, opt_output)) {\r
+      ofilename = setOutputFilename(ifilename);\r
+    }\r
+\r
+    std::ifstream ifs(ifilename.c_str(), std::ios::in);\r
+    if (!ifs) {\r
+      std::cerr << "Cannot open the input file.\n";\r
+      forceQuit();\r
+    }\r
+\r
+    if (isSet(parameters_ready, opt_verbose)) {\r
+      std::cerr << "Input  file: " << ifilename << "\n"\r
+                << "Output file: " << ofilename << "\n";\r
+    }\r
+\r
+    try {\r
+      qCCntl      = new QCompilerCntl(ifs);\r
+      qCalcUnits  = new QCalcUnits(0);\r
+    } catch (const std::bad_alloc ex) {\r
+      std::cerr << "Failed in memory allocation.\n";\r
+      forceQuit();\r
+    }\r
+\r
+    compile(qCCntl, qCalcUnits);\r
+\r
+    try {\r
+      qBits       = new QBits(qCCntl->GetNumberOfQBits());\r
+    } catch (const std::bad_alloc &ex) {\r
+      std::cerr << "Failed in memory allocation.\n"\r
+                << "This .mcd code needs at least "\r
+                << (1 << (qCCntl->GetNumberOfQBits() + 1 + 3))\r
+                << " bytes to allocate the qubits.\n";\r
+      forceQuit();\r
+    }\r
+\r
+    for (unsigned int i = 0; i < qCalcUnits->size(); i++) {\r
+      if (isSet(parameters_ready, opt_verbose)) {\r
+        std::cerr << std::setw(15) << std::left\r
+                  << (*qCalcUnits)[i]->GetName()\r
+                  << " ... ";\r
+      }\r
+      (*qCalcUnits)[i]->Calc(qBits);\r
+      if (isSet(parameters_ready, opt_verbose)) {\r
+        std::cerr << "OK\n";\r
+      }\r
+    }\r
+\r
+    qBits->SaveToFile(ofilename.c_str());\r
+    delete qBits;\r
+    delete qCCntl;\r
+\r
+    for (unsigned int i = 0; i < qCalcUnits->size(); i++) {\r
+      delete (*qCalcUnits)[i];\r
+    }\r
+    delete qCalcUnits;\r
+    ifs.close();\r
+\r
+    if (isSet(parameters_ready, opt_verbose)) {\r
+      std::cerr << "done." << std::endl;\r
+    }\r
+  }\r
+\r
+  return 0;\r
+}\r
+\r
+//----------------------------------------------------------------------------\r
+/**\r
+ *  Check options\r
+ */\r
+Appoptions checkOption(const char * inOptions) {\r
+  Appoptions retVal = 0;\r
+  inOptions++;\r
+  while ('\0' != *inOptions) {\r
+    switch (*inOptions) {\r
+    case 'h':\r
+      retVal |= opt_help;\r
+      break;\r
+    case 'o':\r
+      retVal |= opt_output;\r
+      break;\r
+    case 'v':\r
+      retVal |= opt_verbose;\r
+      break;\r
+    case 'V':\r
+      retVal |= opt_version;\r
+      break;\r
+    default:\r
+      errorAndQuit("there are some invalid options.");\r
+      break;\r
+    }\r
+    inOptions++;\r
+  }\r
+  return retVal;\r
+}\r
+\r
+//----------------------------------------------------------------------------\r
+/**\r
+ *\r
+ */\r
+void compile(QCompilerCntl * const ioCompiler, QCalcUnits * const ioUnits) {\r
+  QCalcUnit *cu = NULL;\r
+  ioUnits->clear();\r
+\r
+  if (true == ioCompiler->Compile()) {\r
+    unsigned int cntl_size = ioCompiler->GetNumberOfControl();\r
+    for (unsigned int i = 0; i < cntl_size; i++) {\r
+      cu = ioCompiler->AllocateControl(i);\r
+      if (NULL != cu) ioUnits->push_back(cu);\r
+    }\r
+  } else {\r
+    errorAndQuit("Parse error occurred.\n");\r
+  }\r
+}\r
+\r
+//----------------------------------------------------------------------------\r
+/**\r
+ *  Force quit\r
+ */\r
+void forceQuit(void) {\r
+  std::cerr << "Quit forced.\n";\r
+  std::exit(1);\r
+}\r
+\r
+//----------------------------------------------------------------------------\r
+/**\r
+ *  Print usages\r
+ */\r
+void printUsage(void) {\r
+  std::cout << "Usage: " << app_name\r
+            << " [-hvV] [-o output_file] input_file.mcd\n\n"\r
+            << "    -h  show this help\n"\r
+            << "    -v  verbose mode\n"\r
+            << "    -V  show version\n\n"\r
+            << std::flush;\r
+}\r
+\r
+//----------------------------------------------------------------------------\r
+/**\r
+ *  Print version\r
+ */\r
+void printVersion(void) {\r
+  std::cout << "\nCopyright (C) 2002-2003 QCAD project\n"\r
+            << app_name << " version " << app_version << "\n\n"\r
+            << std::flush;\r
+}\r
+\r
+//----------------------------------------------------------------------------\r
+/**\r
+ *  Show message and quit\r
+ */\r
+void errorAndQuit(const char * const inMessage) {\r
+  std::cerr << "Error: " << inMessage << "\n\n";\r
+  printUsage();\r
+  forceQuit();\r
+}\r
+\r
+//----------------------------------------------------------------------------\r
+/**\r
+ *  Set output filename\r
+ */\r
+std::string setOutputFilename(const std::string &inString) {\r
+  std::string retString = "";\r
+\r
+  unsigned int posdot = inString.rfind(".", inString.length() - 1);\r
+\r
+  if (posdot == std::string::npos) {\r
+    retString = inString;\r
+  } else {\r
+    retString.assign(inString, 0, posdot);\r
+  }\r
+\r
+  retString += ".qdt";\r
+\r
+  return retString;\r
+}\r
+\r
diff --git a/compiler/sample.mcd b/compiler/sample.mcd
new file mode 100644 (file)
index 0000000..998c3c5
--- /dev/null
@@ -0,0 +1,5 @@
+# file name: "C:\cygwin\home\jun\source\qcad-dev\qcad\compiler\sample.mcd"\r
+# QCAD MIDCODE\r
+INIT(7)\r
+H(q[0])\r
+MEASURE(q[0])\r
diff --git a/compiler/sample.qcd b/compiler/sample.qcd
new file mode 100644 (file)
index 0000000..d927426
--- /dev/null
@@ -0,0 +1,20 @@
+#QCAD - SaveData\r
+7\r
+17\r
+1,0,QWalsh,""\r
+1,1,QWalsh,""\r
+1,2,QWalsh,""\r
+2,4,QCNot,"2"\r
+3,5,QCNot,"2"\r
+4,5,QCNot,"3"\r
+5,3,QCCNot,"1,5"\r
+6,5,QCNot,"3"\r
+7,4,QCNot,"6"\r
+8,6,QCCNot,"1,4"\r
+9,4,QCNot,"6"\r
+10,0,QWalsh,""\r
+11,1,QCRot,"0,90"\r
+12,1,QWalsh,""\r
+13,2,QCRot,"0,45"\r
+14,2,QCRot,"1,90"\r
+15,2,QWalsh,""\r
diff --git a/htdocs/img/00new.png b/htdocs/img/00new.png
new file mode 100644 (file)
index 0000000..cc81793
Binary files /dev/null and b/htdocs/img/00new.png differ
diff --git a/htdocs/img/01open.png b/htdocs/img/01open.png
new file mode 100644 (file)
index 0000000..5e352ed
Binary files /dev/null and b/htdocs/img/01open.png differ
diff --git a/htdocs/img/02save.png b/htdocs/img/02save.png
new file mode 100644 (file)
index 0000000..c40b2ce
Binary files /dev/null and b/htdocs/img/02save.png differ
diff --git a/htdocs/img/03undo.png b/htdocs/img/03undo.png
new file mode 100644 (file)
index 0000000..2c7b954
Binary files /dev/null and b/htdocs/img/03undo.png differ
diff --git a/htdocs/img/04remove.png b/htdocs/img/04remove.png
new file mode 100644 (file)
index 0000000..ec4255b
Binary files /dev/null and b/htdocs/img/04remove.png differ
diff --git a/htdocs/img/05help.png b/htdocs/img/05help.png
new file mode 100644 (file)
index 0000000..2f596fd
Binary files /dev/null and b/htdocs/img/05help.png differ
diff --git a/htdocs/img/06run.png b/htdocs/img/06run.png
new file mode 100644 (file)
index 0000000..45bfb59
Binary files /dev/null and b/htdocs/img/06run.png differ
diff --git a/htdocs/img/07saveasbmp.png b/htdocs/img/07saveasbmp.png
new file mode 100644 (file)
index 0000000..d47c4e0
Binary files /dev/null and b/htdocs/img/07saveasbmp.png differ
diff --git a/htdocs/img/08saveasps.png b/htdocs/img/08saveasps.png
new file mode 100644 (file)
index 0000000..fcbace3
Binary files /dev/null and b/htdocs/img/08saveasps.png differ
diff --git a/htdocs/img/arrow.png b/htdocs/img/arrow.png
new file mode 100644 (file)
index 0000000..94abebb
Binary files /dev/null and b/htdocs/img/arrow.png differ
diff --git a/htdocs/img/ccnot.png b/htdocs/img/ccnot.png
new file mode 100644 (file)
index 0000000..786584a
Binary files /dev/null and b/htdocs/img/ccnot.png differ
diff --git a/htdocs/img/cnot.png b/htdocs/img/cnot.png
new file mode 100644 (file)
index 0000000..7f67c16
Binary files /dev/null and b/htdocs/img/cnot.png differ
diff --git a/htdocs/img/copy.png b/htdocs/img/copy.png
new file mode 100644 (file)
index 0000000..145dc73
Binary files /dev/null and b/htdocs/img/copy.png differ
diff --git a/htdocs/img/crot.png b/htdocs/img/crot.png
new file mode 100644 (file)
index 0000000..21d874a
Binary files /dev/null and b/htdocs/img/crot.png differ
diff --git a/htdocs/img/cswap.png b/htdocs/img/cswap.png
new file mode 100644 (file)
index 0000000..30ce0ce
Binary files /dev/null and b/htdocs/img/cswap.png differ
diff --git a/htdocs/img/cut.png b/htdocs/img/cut.png
new file mode 100644 (file)
index 0000000..251270d
Binary files /dev/null and b/htdocs/img/cut.png differ
diff --git a/htdocs/img/download.png b/htdocs/img/download.png
new file mode 100644 (file)
index 0000000..332aa4e
Binary files /dev/null and b/htdocs/img/download.png differ
diff --git a/htdocs/img/edit.png b/htdocs/img/edit.png
new file mode 100644 (file)
index 0000000..47b3f86
Binary files /dev/null and b/htdocs/img/edit.png differ
diff --git a/htdocs/img/epsexport.png b/htdocs/img/epsexport.png
new file mode 100644 (file)
index 0000000..fa55e80
Binary files /dev/null and b/htdocs/img/epsexport.png differ
diff --git a/htdocs/img/erase.png b/htdocs/img/erase.png
new file mode 100644 (file)
index 0000000..cec8407
Binary files /dev/null and b/htdocs/img/erase.png differ
diff --git a/htdocs/img/measure.png b/htdocs/img/measure.png
new file mode 100644 (file)
index 0000000..6ddf149
Binary files /dev/null and b/htdocs/img/measure.png differ
diff --git a/htdocs/img/measure2.png b/htdocs/img/measure2.png
new file mode 100644 (file)
index 0000000..52bbe12
Binary files /dev/null and b/htdocs/img/measure2.png differ
diff --git a/htdocs/img/measurement1.png b/htdocs/img/measurement1.png
new file mode 100755 (executable)
index 0000000..0f811fc
Binary files /dev/null and b/htdocs/img/measurement1.png differ
diff --git a/htdocs/img/measurement2.png b/htdocs/img/measurement2.png
new file mode 100755 (executable)
index 0000000..2026011
Binary files /dev/null and b/htdocs/img/measurement2.png differ
diff --git a/htdocs/img/measurement3.png b/htdocs/img/measurement3.png
new file mode 100755 (executable)
index 0000000..2e7701f
Binary files /dev/null and b/htdocs/img/measurement3.png differ
diff --git a/htdocs/img/measurement4.png b/htdocs/img/measurement4.png
new file mode 100755 (executable)
index 0000000..a658988
Binary files /dev/null and b/htdocs/img/measurement4.png differ
diff --git a/htdocs/img/mesure.png b/htdocs/img/mesure.png
new file mode 100644 (file)
index 0000000..e63781c
Binary files /dev/null and b/htdocs/img/mesure.png differ
diff --git a/htdocs/img/mesure2.png b/htdocs/img/mesure2.png
new file mode 100644 (file)
index 0000000..e5a7e83
Binary files /dev/null and b/htdocs/img/mesure2.png differ
diff --git a/htdocs/img/not.png b/htdocs/img/not.png
new file mode 100644 (file)
index 0000000..ee45f84
Binary files /dev/null and b/htdocs/img/not.png differ
diff --git a/htdocs/img/paste.png b/htdocs/img/paste.png
new file mode 100644 (file)
index 0000000..9b507ba
Binary files /dev/null and b/htdocs/img/paste.png differ
diff --git a/htdocs/img/qcad.png b/htdocs/img/qcad.png
new file mode 100644 (file)
index 0000000..8cbca02
Binary files /dev/null and b/htdocs/img/qcad.png differ
diff --git a/htdocs/img/qcad1.png b/htdocs/img/qcad1.png
new file mode 100644 (file)
index 0000000..ab3fb58
Binary files /dev/null and b/htdocs/img/qcad1.png differ
diff --git a/htdocs/img/qcad2.png b/htdocs/img/qcad2.png
new file mode 100644 (file)
index 0000000..e2d9531
Binary files /dev/null and b/htdocs/img/qcad2.png differ
diff --git a/htdocs/img/qcad3.png b/htdocs/img/qcad3.png
new file mode 100644 (file)
index 0000000..3ace02e
Binary files /dev/null and b/htdocs/img/qcad3.png differ
diff --git a/htdocs/img/qcad4.png b/htdocs/img/qcad4.png
new file mode 100644 (file)
index 0000000..b623019
Binary files /dev/null and b/htdocs/img/qcad4.png differ
diff --git a/htdocs/img/qcadico48.png b/htdocs/img/qcadico48.png
new file mode 100644 (file)
index 0000000..a1304a1
Binary files /dev/null and b/htdocs/img/qcadico48.png differ
diff --git a/htdocs/img/qcadps.png b/htdocs/img/qcadps.png
new file mode 100644 (file)
index 0000000..31ff3a0
Binary files /dev/null and b/htdocs/img/qcadps.png differ
diff --git a/htdocs/img/qcadr1.png b/htdocs/img/qcadr1.png
new file mode 100644 (file)
index 0000000..c7ed30a
Binary files /dev/null and b/htdocs/img/qcadr1.png differ
diff --git a/htdocs/img/qcadr1_s.png b/htdocs/img/qcadr1_s.png
new file mode 100644 (file)
index 0000000..303e04e
Binary files /dev/null and b/htdocs/img/qcadr1_s.png differ
diff --git a/htdocs/img/qcadr2.png b/htdocs/img/qcadr2.png
new file mode 100644 (file)
index 0000000..1bf34bb
Binary files /dev/null and b/htdocs/img/qcadr2.png differ
diff --git a/htdocs/img/qcadr2_s.png b/htdocs/img/qcadr2_s.png
new file mode 100644 (file)
index 0000000..0ff5768
Binary files /dev/null and b/htdocs/img/qcadr2_s.png differ
diff --git a/htdocs/img/qcadr3.png b/htdocs/img/qcadr3.png
new file mode 100644 (file)
index 0000000..8ae1ae5
Binary files /dev/null and b/htdocs/img/qcadr3.png differ
diff --git a/htdocs/img/qcadr3_s.png b/htdocs/img/qcadr3_s.png
new file mode 100644 (file)
index 0000000..5268f92
Binary files /dev/null and b/htdocs/img/qcadr3_s.png differ
diff --git a/htdocs/img/qcadr4.png b/htdocs/img/qcadr4.png
new file mode 100644 (file)
index 0000000..069c925
Binary files /dev/null and b/htdocs/img/qcadr4.png differ
diff --git a/htdocs/img/qcadr4_s.png b/htdocs/img/qcadr4_s.png
new file mode 100644 (file)
index 0000000..b23a68c
Binary files /dev/null and b/htdocs/img/qcadr4_s.png differ
diff --git a/htdocs/img/qcads.png b/htdocs/img/qcads.png
new file mode 100644 (file)
index 0000000..2717187
Binary files /dev/null and b/htdocs/img/qcads.png differ
diff --git a/htdocs/img/qcads_s.png b/htdocs/img/qcads_s.png
new file mode 100644 (file)
index 0000000..68f1ea6
Binary files /dev/null and b/htdocs/img/qcads_s.png differ
diff --git a/htdocs/img/qgates.png b/htdocs/img/qgates.png
new file mode 100644 (file)
index 0000000..897eed2
Binary files /dev/null and b/htdocs/img/qgates.png differ
diff --git a/htdocs/img/rot.png b/htdocs/img/rot.png
new file mode 100644 (file)
index 0000000..40c1480
Binary files /dev/null and b/htdocs/img/rot.png differ
diff --git a/htdocs/img/swap.png b/htdocs/img/swap.png
new file mode 100644 (file)
index 0000000..6ef3aab
Binary files /dev/null and b/htdocs/img/swap.png differ
diff --git a/htdocs/img/walsh.png b/htdocs/img/walsh.png
new file mode 100644 (file)
index 0000000..d2b9177
Binary files /dev/null and b/htdocs/img/walsh.png differ
diff --git a/htdocs/img/x.png b/htdocs/img/x.png
new file mode 100644 (file)
index 0000000..a56027f
Binary files /dev/null and b/htdocs/img/x.png differ
diff --git a/htdocs/img/y.png b/htdocs/img/y.png
new file mode 100644 (file)
index 0000000..c14967a
Binary files /dev/null and b/htdocs/img/y.png differ
diff --git a/htdocs/img/z.png b/htdocs/img/z.png
new file mode 100644 (file)
index 0000000..22f48b2
Binary files /dev/null and b/htdocs/img/z.png differ
diff --git a/htdocs/index.html b/htdocs/index.html
new file mode 100644 (file)
index 0000000..8bcf9bf
--- /dev/null
@@ -0,0 +1,127 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html lang="en">
+<head>
+<title>QCAD - CAD for Quantum Computer Simulator</title>
+<META http-equiv="Content-Style-Type" content="text/css">
+<link rel="stylesheet" href="style.css" type="text/css">
+</STYLE>
+</head>
+<body>
+<H1>QCAD</H1>
+<div align=center>
+<H2>GUI environment for Quantum Computer Simulator</H2>
+English/<a href="index_j.html">Japanese</a>
+</div>
+<hr>
+<H2> About QCAD </H2>
+<P><img src="img/qcadico48.png"></P>
+<P>
+   "QCAD" is a windows-based environment for quantum computing simulation
+which helps you designing circuits and simulating them.</P>
+<H3>Functions</H3>
+<P>
+GUI Environment to design quantum circuits:<BR>
+- QCAD enables you to design quantum circuits easily with full GUI(graphical user interface) environment. <BR>
+</P>
+<P>Export-able EPS and BMP:<BR>
+- QCAD can export the designed circuits as Encapsulated Postscript(EPS) in order to include in LaTeX files. <BR>
+</P>
+<P>Builtin Simulator:<BR>
+- QCAD can simulate the designed circuited and show results(states of qubits).<BR>
+</P>
+<HR>
+<H2>Screen Shots</H2>
+
+<P>
+<H3>Execution Images</H3>
+(click to get a larger image)<BR>
+<a href="img/qcads.png"><img src="img/qcads_s.png"></a><P>
+<H3>Result Images</H3>
+<P>
+<a href="img/qcadr1.png"><img src="img/qcadr1_s.png" ></a>
+<a href="img/qcadr2.png"><img src="img/qcadr2_s.png" ></a>
+<a href="img/qcadr3.png"><img src="img/qcadr3_s.png" ></a>
+<a href="img/qcadr4.png"><img src="img/qcadr4_s.png" ></a>
+</P>
+<P>
+EPS file created by QCAD<BR>
+<img src="img/epsexport.png">
+</P>
+<H2>Download</H2>
+<P>
+  Get the latest release of QCAD from <a href="http://sourceforge.jp/projects/qcad/releases/">here</a>.
+</P>
+<HR>
+<H2>System Requirements</H2>
+<ul>
+<li> Windows XP/Vista or later.
+<li> Enough memory. If you want to simulate a large circuits, please be careful.
+</ul>
+<HR>
+<H2>Online Document</H2>
+<P>
+  For detailed information, refer to <a href="qcadhelp.html">Online QCAD help file</a>.</P>
+<HR>
+<H2> Related software </H2>
+<P><a href="http://rugth30.phys.rug.nl/compphys0/qce.htm">QCE</a> is a software tool that emulates various hardware designs of Quantum Computers. 
+(University of Groningen, The Netherlands)</P>
+<HR>
+<H2>License</H2>
+
+<P>
+Copyright &copy; 2002 - 2011 QCAD Developers Team
+</P>
+<P>
+Redistribution and use in source and binary forms, with or without modification, are
+permitted provided that the following conditions are met:
+</P>
+
+<ol>
+<li> In any scientific publication based wholly or in part on the Software, the use of the Software must be acknowledged.
+<li> Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+<li> 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.
+</ol>
+
+<pre>
+THIS SOFTWARE IS PROVIDED ''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 <COPYRIGHT HOLDER> OR
+CONTRIBUTORS 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.
+</pre>
+<HR>
+<H2>About Developers</H2>
+<ul>
+<li> Hiroshi Watanabe (Representative)
+<li> Masaru Suzuki (Programmer)
+<li> Junnosuke Yamazaki (Programmer) 
+</ul>
+<HR>
+<H2>Known Problems</H2>
+<P>
+QCAD has some problems as following.
+<ol>
+<li> Measurement gates on QCAD are different from real measurements. See the helpfile for detail.
+<li> Step-by-step execution is not available yet.
+</ol>
+</P>
+<HR>
+<H2>Acknowledgements</H2>
+<P>
+This work is supported by a grant under the youth section of Exploratory
+Software Project FY2002 (IPA, Japan). This software was developed
+at the University of Tokyo and Nagoya University.
+</P>
+<hr>
+<div class="footer">\r
+QCAD &lt;<a href="http://qcad.sourceforge.jp">http://qcad.sourceforge.jp</a>&gt;\r
+<br>Copyright &copy; 2002-2011 QCAD Developers Team  All rights reserved.<br>\r
+E-mail: <a href="m&#97;&#105;&#108;to&#58;&#107;&#97;&#105;ty&#111;&#64;&#117;sers.so&#117;rc&#101;f&#111;&#114;&#103;&#101;.j&#112;">k&#97;it&#121;o&#64;u&#115;&#101;&#114;s.&#115;&#111;ur&#99;efo&#114;ge&#46;j&#112;</a><BR>\r
+Powered by <a href="http://sourceforge.jp/"><img src="http://sourceforge.jp/sflogo.php?group_id=5966&type=1" width="96" height="31" border="0" alt="SourceForge.JP"></a>\r
+</div>
+</body>
+</html>
diff --git a/htdocs/index_j.html b/htdocs/index_j.html
new file mode 100644 (file)
index 0000000..1a087bb
--- /dev/null
@@ -0,0 +1,121 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html lang="ja">
+<head>
+<title>QCAD - CAD for Quantum Computer Simulator</title>
+<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
+<link rel="stylesheet" href="style.css" type="text/css">
+</STYLE>
+</head>
+<body>
+<H1>QCAD</H1>
+<div align=center>
+<H2>GUI environment for Quantum Computer Simulator</H2>
+<a href="index.html">English</a>/Japanese
+</div>
+<hr>
+<H2>\82±\82Ì\83\\83t\83g\83E\83F\83A\82É\82Â\82¢\82Ä</H2>
+<P><img src="img/qcadico48.png"></P>
+<P>
+\81@QCAD\82Í\81A\97Ê\8eq\8cv\8eZ\8b@\97p\82Ì\89ñ\98H\90}\82ð\8dì\82é\82½\82ß\82Ì\83\\83t\83g\82Å\82·\81B
+GUI\82Å\8aÈ\92P\82É\89ñ\98H\90}\82ª\8f\91\82¯\82Ü\82·\81B\8f\91\82¢\82½\89ñ\98H\82Í\93Æ\8e©\8c`\8e®\82Ì\82Ù\82©\81Aeps\8c`\8e®\81Abitmap\8c`\8e®\82Å\95Û\91\82Å\82«\82Ü\82·\81B
+\8dì\90¬\82µ\82½\89ñ\98H\82Í\82»\82Ì\8fê\82Å\83V\83~\83\85\83\8c\81[\83g\82µ\81A\8c\8b\89Ê\82ð\95\\8e¦\82·\82é\82±\82Æ\82ª\82Å\82«\82Ü\82·\81B
+</P>
+<HR>
+<H2>\83X\83N\83\8a\81[\83\93\83V\83\87\83b\83g</H2>
+
+<P>
+<H3>\8eÀ\8ds\89æ\96Ê</H3>
+(click to get a larger image)<BR>
+<a href="img/qcads.png"><img src="img/qcads_s.png"></a><P>
+<H3>\8c\8b\89Ê\8fo\97Í\89æ\96Ê</H3>
+<P>
+<a href="img/qcadr1.png"><img src="img/qcadr1_s.png" ></a>
+<a href="img/qcadr2.png"><img src="img/qcadr2_s.png" ></a>
+<a href="img/qcadr3.png"><img src="img/qcadr3_s.png" ></a>
+<a href="img/qcadr4.png"><img src="img/qcadr4_s.png" ></a>
+</P>
+<P>
+\8fo\97Í\82µ\82½eps\83C\83\81\81[\83W<BR>
+<img src="img/epsexport.png">
+</P>
+<H2>Download</H2>
+<P>
+  QCAD\82Ì\8dÅ\90V\94Å\82Í <a href="http://sourceforge.jp/projects/qcad/releases/">\82±\82¿\82ç</a>\82æ\82è\83_\83E\83\93\83\8d\81[\83h\82µ\82Ä\82­\82¾\82³\82¢\81B
+</P>
+<HR>
+<H2>\93®\8dì\8aÂ\8b«</H2>
+<ul>
+<li> Windows XP/Vista\81A\82à\82µ\82­\82Í\82»\82ê\88È\8d~\82ÌWindows (Mac\81ALinux\82Å\82Í\93®\8dì\82µ\82Ü\82¹\82ñ)\81B
+<li> \8f\\95ª\82È\83\81\83\82\83\8a\81B\97Ê\8eq\8cv\8eZ\83V\83~\83\85\83\8c\81[\83V\83\87\83\93\82É\82Í\91½\82­\82Ì\83\81\83\82\83\8a\82ð\95K\97v\82Æ\82µ\82Ü\82·\81B
+\91å\82«\82È\89ñ\98H\82ð\83V\83~\83\85\83\8c\81[\83g\82·\82é\8dÛ\82É\82Í\8f\\95ª\92\8d\88Ó\82µ\82Ä\82­\82¾\82³\82¢\81B
+</ul>
+<HR>
+<H2>\83I\83\93\83\89\83C\83\93\83w\83\8b\83v</H2>
+<P>
+  \88È\89º\82ÅQCAD\82Ì\83w\83\8b\83v(\89p\8cê)\82ð\8eQ\8fÆ\82Å\82«\82Ü\82·\81B
+\81¨<a href="qcadhelp.html">Online QCAD help file</a>
+</P>
+<HR>
+<H2> \8aÖ\98A\83\\83t\83g\83E\83F\83A </H2>
+<P><a href="http://rugth30.phys.rug.nl/compphys0/qce.htm">QCE</a>\81F
+\83O\83\8d\81[\83j\83\93\83Q\83\93\91å\8aw(\83I\83\89\83\93\83_)\82Å\8aJ\94­\82³\82ê\82½\97Ê\8eq\8cv\8eZ\83V\83~\83\85\83\8c\81[\83^\82Å\82·\81B
+</P>
+<HR>
+<H2>\83\89\83C\83Z\83\93\83X</H2>
+
+<P>
+Copyright &copy; 2002 - 2011 QCAD Developers Team
+</P>
+<P>
+\83\\81[\83X\83R\81[\83h\81A\83o\83C\83i\83\8a\82È\82Ç\82Ì\94z\95z\8c`\8e®\81A\8by\82Ñ\95Ï\8dX\82Ì\97L\96³\82ð\96â\82í\82¸\81A\88È\89º\82Ì\8fð\8c\8f\82ð\96\9e\82½\82·\8cÀ\82è\82É\82¨\82¢\82Ä\81A\8dÄ\94z\95z\8by\82Ñ\8eg\97p\82ð\8b\96\89Â\82µ\82Ü\82·\81B
+</P>
+<ol>
+<li> \96{\83\\83t\83g\83E\83F\83A\82ð\97\98\97p\82µ\82Ä\93¾\82ç\82ê\82½\8c\8b\89Ê\82ð\98_\95\82â\82»\82Ì\91¼\82Ì\8fo\94Å\95¨\82É\8bL\8dÚ\82·\82é\8dÛ\81A\96{\83\\83t\83g\83E\83F\83A\82ð\97\98\97p\82µ\82½\82±\82Æ\82ð\98_\95\92\86\82É\96¾\8bL\82·\82é\82±\82Æ\81B
+<li> \83\\81[\83X\83R\81[\83h\8c`\8e®\82Å\8dÄ\94z\95z\82·\82é\8fê\8d\87\81A\8fã\8bL\92\98\8dì\8c \95\\8e¦\81A\96{\8fð\8c\8f\8f\91\8by\82Ñ\89º\8bL\90Ó\94C\8cÀ\92è\8bK\92è\82ð\95K\82¸\8aÜ\82ß\82é\82±\82Æ\81B
+<li> \83o\83C\83i\83\8a\8c`\8e®\82Å\8dÄ\94z\95z\82·\82é\8fê\8d\87\81A\8fã\8bL\92\98\8dì\8c \95\\8e¦\81A\96{\8fð\8c\8f\8f\91\8by\82Ñ\89º\8bL\90Ó\94C\8cÀ\92è\8bK\92è\82ð\81A\94z\95z\95¨\82Æ\82Æ\82à\82É\92ñ\8b\9f\82³\82ê\82é\95\8f\91\81A\82à\82µ\82­\82Í\91¼\82Ì\8e\91\97¿\82É\95K\82¸\8aÜ\82ß\82é\8e\96\81B
+</ol>\r
+<pre>\r
+\96{\83\\83t\83g\83E\83F\83A\82Í"\8c»\8fó\82Ì\82Ü\82Ü"\92ñ\8b\9f\82³\82ê\82é\82à\82Ì\82Æ\82·\82é\81B\r
+\96{\83\\83t\83g\83E\83F\83A\82É\82Â\82¢\82Ä\82Í\81A\96¾\8e¦\96Ù\8e¦\82ð\96â\82í\82¸\81A\8f¤\97p\95i\82Æ\82µ\82Ä\92Ê\8fí\82»\82È\82¦\82é\82×\82«\r
+\95i\8e¿\82ð\82»\82È\82¦\82Ä\82¢\82é\82Æ\82Ì\95Û\8fØ\82à\81A\93Á\92è\82Ì\96Ú\93I\82É\93K\8d\87\82·\82é\82Æ\82Ì\95Û\8fØ\82ð\8aÜ\82ß\81A\82Ü\82½\82»\82ê\82ç\82É\r
+\8cÀ\92è\82³\82ê\82È\82¢\82¢\82©\82È\82é\95Û\8fØ\82à\82È\82³\82ê\82È\82¢\81B\92\98\8dì\8c \8eÒ\82à\81A\8e\96\97R\82Ì\82¢\82©\82ñ\82ð\96â\82í\82¸\81A\r
+\91¹\8aQ\94­\90\82Ì\8c´\88ö\82¢\82©\82ñ\82ð\96â\82í\82¸\81A\8a\8e\82Â\81\90Ó\94C\82Ì\8dª\8b\92\82ª\8c_\96ñ\82Å\82 \82é\82©\8cµ\8ai\90Ó\94C\82Å\82 \82é\82©\r
+(\89ß\8e¸\82»\82Ì\91¼)\95s\96@\8ds\88×\82Å\82 \82é\82©\82ð\96â\82í\82¸\81A\92\98\8dì\8c \8eÒ\82ª\89¼\82É\82»\82Ì\82æ\82¤\82È\91¹\8aQ\82ª\94­\90\82·\82é\r
+\89Â\94\\90«\82ð\92m\82ç\82³\82ê\82Ä\82¢\82½\82Æ\82µ\82Ä\82à\81A\96{\83\\83t\83g\83E\83F\83A\82Ì\8eg\97p\82©\82ç\94­\90\82µ\82½(\91ã\91Ö\95i\82Ü\82½\82Í\r
+\83T\81[\83r\83X\82Ì\92ñ\8b\9f\81A\8eg\97p\82Ì\91r\8e¸\81A\83f\81[\83^\82Ü\82½\82Í\97\98\89v\82Ì\91¹\8e¸\82Ì\95â\8f\9e\81A\82Ü\82½\82Í\81A\8bÆ\96±\82Ì\92\86\92f\82É\r
+\91Î\82·\82é\95â\8f\9e\82ð\8aÜ\82ß\81A\82Ü\82½\82»\82ê\82ç\82É\8cÀ\92è\82³\82ê\82È\82¢)\92¼\90Ú\91¹\8aQ\81A\8aÔ\90Ú\91¹\8aQ\81A\8bô\94­\93I\82È\91¹\8aQ\81A\r
+\93Á\95Ê\91¹\8aQ\81A\92¦\94±\93I\91¹\8aQ\82Ü\82½\82Í\8c\8b\89Ê\91¹\8aQ\82Ì\82¢\82¸\82ê\82É\91Î\82µ\82Ä\82à\88ê\90Ø\82Ì\90Ó\94C\82ð\95\89\82í\82È\82¢\81B
+</pre>
+<HR>
+<H2>\8aJ\94­\8eÒ\82É\82Â\82¢\82Ä</H2>
+<P>
+\81@QCAD\82Í\88È\89º\82Ì\8eO\96¼\82É\82æ\82è\8aJ\94­\82³\82ê\82Ü\82µ\82½\81B
+</P>
+<ul>
+<li> \93n\95Ó\92\88\8eu (\91ã\95\)
+<li> \97é\96Ø\8f«
+<li> \8eR\8dè\8f~\94V\89î
+</ul>
+<HR>
+<h2>\8c»\8dÝ\82Ì\8ed\97l</h2>\r
+<ol>\r
+<li> Measurement Gate\82Í\81A\92Ê\8fí\82Ì\91ª\92è\82Æ\93®\8dì\82ª\88Ù\82È\82è\82Ü\82·\81B\8fÚ\82µ\82­\82Í\83w\83\8b\83v\82ð\8eQ\8fÆ\82µ\82Ä\82­\82¾\82³\82¢\81B\r
+<li> \83X\83e\83b\83v\8eÀ\8ds\82È\82Ç\82Ì\83f\83o\83b\83O\8b@\94\\82Í\82Ü\82¾\8eÀ\91\95\82³\82ê\82Ä\82¨\82è\82Ü\82¹\82ñ\81B\r
+</ol>
+<HR>
+<H2>\8eÓ\8e«</H2>
+<P>
+\81@QCAD\83v\83\8d\83W\83F\83N\83g\82Í\81A\8fî\95ñ\8f\88\97\9d\90U\8b»\8e\96\8bÆ\8b¦\89ï\82Ì\8cö\95å\8e\96\8bÆ\81A\95½\90¬\82P\82S\94N\93x\96¢\93¥\83\\83t\83g\83E\83F\83A\91n\91¢\r
+\8e\96\8bÆ\81u\96¢\93¥\83\86\81[\83X\81v\82É\8dÌ\91ð\82³\82ê\82½\82à\82Ì\82Å\82·\81B\83v\83\8d\83W\83F\83N\83g\83}\83l\81[\83W\83\83\82Ì\92|\93à\88è\97Y\90æ\90\81A\82¨\82æ\82Ñ
+\83v\83\8d\83W\83F\83N\83g\8aÇ\97\9d\82ð\82µ\82Ä\82­\82¾\82³\82Á\82½\92r\93c\97l\82É\8a´\8eÓ\82¢\82½\82µ\82Ü\82·\81B
+\82Ü\82½\81A\82±\82Ì\83\\83t\83g\83E\83F\83A\82Í\93\8c\8b\9e\91å\8aw\82¨\82æ\82Ñ\96¼\8cÃ\89®\91å\8aw\82É\82¨\82¢\82Ä\8aJ\94­\82³\82ê\82Ü\82µ\82½\81B
+</P>
+<hr>
+<div class="footer">\r
+QCAD &lt;<a href="http://qcad.sourceforge.jp">http://qcad.sourceforge.jp</a>&gt;\r
+<br>Copyright &copy; 2002-2011 QCAD Developers Team  All rights reserved.<br>\r
+E-mail: <a href="m&#97;&#105;&#108;to&#58;&#107;&#97;&#105;ty&#111;&#64;&#117;sers.so&#117;rc&#101;f&#111;&#114;&#103;&#101;.j&#112;">k&#97;it&#121;o&#64;u&#115;&#101;&#114;s.&#115;&#111;ur&#99;efo&#114;ge&#46;j&#112;</a><BR>\r
+Powered by <a href="http://sourceforge.jp/"><img src="http://sourceforge.jp/sflogo.php?group_id=5966&type=1" width="96" height="31" border="0" alt="SourceForge.JP"></a>\r
+</div>
+</body>
+</html>
diff --git a/htdocs/makefile b/htdocs/makefile
new file mode 100644 (file)
index 0000000..59df2b5
--- /dev/null
@@ -0,0 +1,27 @@
+TARGET=qcadhelp
+TITLE="QCAD Help File"
+RD=rd2
+RDOPT=-r rd/rd2html-ext-lib.rb --ref-extension --head-element --with-part=head:head --html-title=$(TITLE) --native-inline
+HHC='/cygdrive/c/Program Files/HTML Help Workshop/hhc'
+
+.SUFFIXES: .rd .html .chm .hhc
+
+all:$(TARGET).chm
+
+$(TARGET).chm: $(TARGET).hhc
+
+$(TARGET).hhc: $(TARGET).html
+
+$(TARGET).html: $(TARGET).rd
+
+.html.hhc:
+       ruby makehhc.rb $(TARGET).html > $(TARGET).hhc
+
+.rd.html:
+       $(RD) $(RDOPT) $< > $@
+
+.html.chm:
+       $(HHC) $*.hhp
+
+clean:
+       rm -f $(TARGET).html $(TARGET).chm $(TARGET).hhc
diff --git a/htdocs/makehhc.rb b/htdocs/makehhc.rb
new file mode 100644 (file)
index 0000000..13f0b3b
--- /dev/null
@@ -0,0 +1,46 @@
+def modline(line)
+  if line=~/a href=(.*)>(.*)<\/a/
+    label = $1
+    name = $2
+    label.gsub!(/\"/,"")
+    puts "<li><OBJECT type=\"text/sitemap\"><param name=\"Name\" value=\"#{name}\">"
+    puts "<param name=\"Local\" value=\"qcadhelp.html#{label}\">"
+    puts "</OBJECT>"
+  elsif line=~/<li>(.*)/
+    name = $1
+    puts "<li><OBJECT type=\"text/sitemap\"><param name=\"Name\" value=\"#{name}\">"
+    puts "</OBJECT>"
+  else
+    print line
+  end
+end
+
+def putheader
+print <<EOS
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">\r
+<HTML>\r
+<HEAD>\r
+<meta name="GENERATOR" content="Microsoft&reg; HTML Help Workshop 4.1">\r
+<!-- Sitemap 1.0 -->\r
+</HEAD><BODY>\r
+EOS
+end
+
+def putfooter
+  puts "</BODY></HTML>"
+end
+
+putheader
+
+flag = false
+while line=gets
+  if line=~/label-1/
+    flag = true
+    next
+  elsif line=~/h2/
+    putfooter
+    exit
+  end
+  modline(line) if flag
+end
+
diff --git a/htdocs/qcadhelp.hhp b/htdocs/qcadhelp.hhp
new file mode 100644 (file)
index 0000000..7d61160
--- /dev/null
@@ -0,0 +1,15 @@
+[OPTIONS]\r
+Compatibility=1.1 or later\r
+Compiled file=qcadhelp.chm\r
+Contents file=qcadhelp.hhc\r
+Default topic=qcadhelp.html\r
+Display compile progress=No\r
+Language=0x409 \89p\8cê (\95Ä\8d\91)\r
+Title=Copal Pro Help File\r
+\r
+\r
+[FILES]\r
+qcadhelp.html\r
+\r
+[INFOTYPES]\r
+\r
diff --git a/htdocs/qcadhelp.html b/htdocs/qcadhelp.html
new file mode 100644 (file)
index 0000000..2ac1175
--- /dev/null
@@ -0,0 +1,386 @@
+<?xml version="1.0" ?>
+<!DOCTYPE html 
+  PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<title>QCAD Help File</title>
+<!-- head-element:nil -->
+</head>
+<body>
+<title>Qcad Help File</title>\r
+<META http-equiv="Content-Style-Type" content="text/css">\r
+<STYLE TYPE="text/css">\r
+<!--\r
+body {line-height: 120%;  background-color:#ffffd2; color: black}\r
+A:link { text-decoration:none; font-weight:bold; color:#161FFA }\r
+A:visited { text-decoration:none; font-weight:bold; color:#06AAFF }\r
+A:active { text-decoration:none; font-weight:bold; color:#8470FF }\r
+A:hover { font-weight:bold; color:#FF707F }\r
+H1 {padding-top:10px;text-align: center}\r
+H2 {padding-top:10px;border-top: black 1px solid;}\r
+code {padding:10px; display:block;white-space:pre;border: solid 1px #AAAAAA;}\r
+dt{font-weight:bold;}\r
+div.footer{text-align:center;color:#800000;}\r
+-->\r
+</STYLE>\r
+
+<h1><a name="label-0" id="label-0">QCAD - HelpFile</a></h1><!-- RDLabel: "QCAD - HelpFile" -->
+<p><div align=center><img src="img/qcadico48.png"></div></p>
+<p>QCAD is a windows-based GUI environment of Quantum Computing Simulation, it will help you to study quantum computations. </p>
+<p>This software has following functions.</p>
+<ol>
+<li>Graphical Designing Environment for Quantum Circuits.</li>
+<li>Quantum Simulator</li>
+<li>Exportable EPS and Bitmap file of circuits designed by QCAD.</li>
+</ol>
+<h2><a name="label-1" id="label-1">Table of contents</a></h2><!-- RDLabel: "Table of contents" -->
+<ul>
+<li>About:
+<ul>
+<li><a href="#label-2">Specifications</a></li>
+<li><a href="#label-9">Installation &amp; Uninstallation</a></li>
+</ul></li>
+<li>Design Circuits:
+<ul>
+<li><a href="#label-12">Edit Window</a></li>
+<li><a href="#label-15">Circuit Panel</a></li>
+<li><a href="#label-16">Available Quantum Gates</a></li>
+<li><a href="#label-19">Save &amp; Load</a></li>
+<li><a href="#label-20">Export Other Format</a></li>
+</ul></li>
+<li>Menu References:
+<ul>
+<li><a href="#label-23">Menu References</a></li>
+</ul></li>
+<li>Simulator:
+<ul>
+<li><a href="#label-43">Simulate Circuit</a></li>
+<li><a href="#label-44">Measurement</a></li>
+<li><a href="#label-46">Save Results</a></li>
+</ul></li>
+<li>Other Information:
+<ul>
+<li><a href="#label-49">Known Problems</a></li>
+<li><a href="#label-50">About Developers</a></li>
+<li><a href="#label-51">License</a></li>
+<li><a href="#label-52">Acknowledgements</a></li>
+<li><a href="#label-53">History</a></li>
+</ul></li>
+</ul>
+<h2><a name="label-2" id="label-2">Specifications</a></h2><!-- RDLabel: "Specifications" -->
+<h3><a name="label-3" id="label-3">Functions</a></h3><!-- RDLabel: "Functions" -->
+<dl>
+<dt><a name="label-4" id="label-4">GUI Environment to design quantum circuits</a></dt><!-- RDLabel: "GUI Environment to design quantum circuits" -->
+<dd>
+QCAD enables you to design quantum circuits easily with full GUI (graphical user interface) environment. 
+</dd>
+<dt><a name="label-5" id="label-5">Exportable EPS and BMP</a></dt><!-- RDLabel: "Exportable EPS and BMP" -->
+<dd>
+QCAD can export the designed circuits as Encapsulated PostScript (EPS) in order to include in LaTeX files. 
+</dd>
+<dt><a name="label-6" id="label-6">Built-in Simulator</a></dt><!-- RDLabel: "Built-in Simulator" -->
+<dd>
+QCAD can simulate the designed circuit and show results (states of qubits).
+</dd>
+</dl>
+<p>See <a href="#label-16">Available Quantum Gates</a>. The matrices of the gates are also shown there.</p>
+<h3><a name="label-7" id="label-7">System Requirements</a></h3><!-- RDLabel: "System Requirements" -->
+<dl>
+<dt><a name="label-8" id="label-8">Operating System</a></dt><!-- RDLabel: "Operating System" -->
+<dd>
+Windows 2000 or higher. QCAD does not work on Linux or Mac OS.
+</dd>
+</dl>
+<h2><a name="label-9" id="label-9">Installation &amp; Uninstallation</a></h2><!-- RDLabel: "Installation & Uninstallation" -->
+<h3><a name="label-10" id="label-10">Installation</a></h3><!-- RDLabel: "Installation" -->
+<ol>
+<li>Unpack the archive file to any folder (e.g. c:\util\qcad).</li>
+<li>Double click the icon of QCAD <img src="img/qcad.png" alt="img/qcad.png" /> to execute it.</li>
+</ol>
+<h3><a name="label-11" id="label-11">Uninstallation</a></h3><!-- RDLabel: "Uninstallation" -->
+<p>Remove installed folder and its contents.</p>
+<p>NOTE:  QCAD will never touch any registries of your system.</p>
+<h2><a name="label-12" id="label-12">Edit Window</a></h2><!-- RDLabel: "Edit Window" -->
+<pre>When QCAD is executed, you can see "Edit Window". You can put gates on it.</pre>
+<dl>
+<dt><a name="label-13" id="label-13">Bitbox</a></dt><!-- RDLabel: "Bitbox" -->
+<dd>
+The left end of it, there are "Bitbox". You can modify the initial states of qubits with it.
+</dd>
+<dt><a name="label-14" id="label-14">Multi Select</a></dt><!-- RDLabel: "Multi Select" -->
+<dd>
+If you want to select many gates at the same time, click gates with the control key. 
+</dd>
+</dl>
+<h2><a name="label-15" id="label-15">Circuit Panel</a></h2><!-- RDLabel: "Circuit Panel" -->
+<pre>Circuit Panel is a circuit selector. </pre>
+<p>You can open it by choosing "Circuit Panel" by "View" menu.</p>
+<pre>Click a button which shows a circuit that you want to put.</pre>
+<p>Then the circuit is selected.</p>
+<p>Next, Click the edit window, then the circuit is put there.</p>
+<pre>If the circuit requires parameter, the parameter window will open.</pre>
+<p>Set all parameters like as control bits, and then push OK. </p>
+<h2><a name="label-16" id="label-16">Available Quantum Gates</a></h2><!-- RDLabel: "Available Quantum Gates" -->
+<ul>
+<li><img src="img/walsh.png" alt="img/walsh.png" /> Walsh Hadamard Gate</li>
+<li><img src="img/not.png" alt="img/not.png" /> Not Gate</li>
+<li><img src="img/cnot.png" alt="img/cnot.png" /> Controlled Not Gate</li>
+<li><img src="img/ccnot.png" alt="img/ccnot.png" /> Toffoli (Controlled Controlled Not) Gate</li>
+<li><img src="img/rot.png" alt="img/rot.png" /> Rotation Gate</li>
+<li><img src="img/crot.png" alt="img/crot.png" /> Controlled Rotation Gate</li>
+<li><img src="img/x.png" alt="img/x.png" /> Pauli X Gate</li>
+<li><img src="img/y.png" alt="img/y.png" /> Pauli Y Gate</li>
+<li><img src="img/z.png" alt="img/z.png" /> Pauli Z Gate</li>
+<li><img src="img/swap.png" alt="img/swap.png" /> Swap Gate</li>
+<li><img src="img/mesure2.png" alt="img/mesure2.png" /> Measurement Gate</li>
+</ul>
+<h3><a name="label-17" id="label-17">Bitbox</a></h3><!-- RDLabel: "Bitbox" -->
+<pre>Gate "Bitbox" are special gates. They are irremovable. You can set the initial value of qubits.</pre>
+<p>If you want to set initial value of qubit as |0...01&gt;, change state of Bitbox at Q1 to "1",</p>
+<p>and "0" for other Bitbox.</p>
+<pre>If you set Enabled to false, the line become disabled. This function is for exporting an EPS file. You can get EPS file with skipping this line.</pre>
+<h3><a name="label-18" id="label-18">Matrices for gates</a></h3><!-- RDLabel: "Matrices for gates" -->
+<p><img src="img/qgates.png" alt="img/qgates.png" /></p>
+<h2><a name="label-19" id="label-19">Save &amp; Load</a></h2><!-- RDLabel: "Save & Load" -->
+<pre>You can save and load the circuit data of QCAD by "Save" and  "Load" options on "File" menu. A default extension is "qcd".</pre>
+<h2><a name="label-20" id="label-20">Export Other Format</a></h2><!-- RDLabel: "Export Other Format" -->
+<h3><a name="label-21" id="label-21">Export EPS</a></h3><!-- RDLabel: "Export EPS" -->
+<pre>You can export a designed circuit as EPS(Encapsulated PostScript) file which is suitable for LaTeX or other types of document.</pre>
+<p>After designing a circuit, choose "Export EPS file".</p>
+<h3><a name="label-22" id="label-22">Export Bitmap File</a></h3><!-- RDLabel: "Export Bitmap File" -->
+<pre>If you need a bitmap file of a designed circuit, you can export a bitmap file which is what you see at the edit window. After designing a circuit, choose "Export as Bitmap file".</pre>
+<h2><a name="label-23" id="label-23">Menu References</a></h2><!-- RDLabel: "Menu References" -->
+<p>The Menus and their short cuts allow quick access to many operations. The Following menus are available.</p>
+<p><a href="#label-24">File Menu</a></p>
+<p><a href="#label-34">View Menu</a></p>
+<p><a href="#label-36">Edit Menu</a></p>
+<p><a href="#label-39">Calc Menu</a></p>
+<p><a href="#label-40">Help Menu</a></p>
+<h2><a name="label-24" id="label-24">File Menu</a></h2><!-- RDLabel: "File Menu" -->
+<p>The File menu allows access to the operations of saving and loading data, exporting as other formats and quitting QCAD.</p>
+<h3><a name="label-25" id="label-25">New</a></h3><!-- RDLabel: "New" -->
+<p><img src="img/00new.png" alt="img/00new.png" /></p>
+<p>Select the "New" option to obtain a new circuit. QCAD will ask you the size of it. If there is an unsaved circuits, the confirm dialog opens, asking for a file name for the designed circuit.</p>
+<h3><a name="label-26" id="label-26">Open</a></h3><!-- RDLabel: "Open" -->
+<p><img src="img/01open.png" alt="img/01open.png" /></p>
+<p>Select the "Open" option to open the designed QCAD file. If there is an unsaved circuits, the confirm dialog opens, asking for a file name for the designed circuit.</p>
+<h3><a name="label-27" id="label-27">Save</a></h3><!-- RDLabel: "Save" -->
+<p><img src="img/02save.png" alt="img/02save.png" /></p>
+<p>Select the "Save" option to save the designed circuit to the file.</p>
+<p>If you have not set the name of file, Save Dialog appears and requires the filename.</p>
+<h3><a name="label-28" id="label-28">Save As</a></h3><!-- RDLabel: "Save As" -->
+<p>Select the "Save As" option to save the designed circuit to the file with desired filename. Save Dialog appears and requires the filename.</p>
+<h3><a name="label-29" id="label-29">Export as EPS file</a></h3><!-- RDLabel: "Export as EPS file" -->
+<p><img src="img/08saveasps.png" alt="img/08saveasps.png" /></p>
+<p>Select the "Export as EPS file" option to export the designed circuit as the EPS(Encapsulated PostScript) file format. This format is suitable for LaTeX or other document to include.</p>
+<h3><a name="label-30" id="label-30">Export as Bitmap file</a></h3><!-- RDLabel: "Export as Bitmap file" -->
+<p><img src="img/07saveasbmp.png" alt="img/07saveasbmp.png" /></p>
+<p>Select the "Export as Bitmap file" option to export the designed circuit as the Bitmap file format. The current format of the bitmap is the type of 8bit(including 256 colors).</p>
+<h3><a name="label-31" id="label-31">Print</a></h3><!-- RDLabel: "Print" -->
+<p>Print the current circuit.</p>
+<h3><a name="label-32" id="label-32">Print Setup</a></h3><!-- RDLabel: "Print Setup" -->
+<p>Setup a printer.</p>
+<h3><a name="label-33" id="label-33">Exit</a></h3><!-- RDLabel: "Exit" -->
+<p>Select the "Exit" option to quit designing and close the QCAD. If there is an unsaved circuits, the confirm dialog opens, asking for a file name for the designed circuit.</p>
+<h2><a name="label-34" id="label-34">View Menu</a></h2><!-- RDLabel: "View Menu" -->
+<p>The View menu allows access to Circuit Panel.</p>
+<h3><a name="label-35" id="label-35">Circuit Panel</a></h3><!-- RDLabel: "Circuit Panel" -->
+<p>Select the Circuit Panel option to open the circuit panel. See &lt;a href="#HLP000011"&gt;Circuit Panel&lt;/a&gt; section for more information.</p>
+<h2><a name="label-36" id="label-36">Edit Menu</a></h2><!-- RDLabel: "Edit Menu" -->
+<p>Edit menu allows to the operations which modify the designing circuit.</p>
+<h3><a name="label-37" id="label-37">Undo</a></h3><!-- RDLabel: "Undo" -->
+<p><img src="img/03undo.png" alt="img/03undo.png" /></p>
+<p>Select the Undo option to undo the previous operations. You can undo all operations and the number of undo is unlimited (it depends on the size of memory of your system).</p>
+<h3><a name="label-38" id="label-38">Remove</a></h3><!-- RDLabel: "Remove" -->
+<p><img src="img/04remove.png" alt="img/04remove.png" /></p>
+<p>Select the Remove option to remove the selected gates.</p>
+<h2><a name="label-39" id="label-39">Calc Menu</a></h2><!-- RDLabel: "Calc Menu" -->
+<p>Edit menu allows to operations to the simulator of the QCAD.</p>
+<p>See <a href="#label-43">Simulate Circuit</a> section for details.</p>
+<h2><a name="label-40" id="label-40">Help Menu</a></h2><!-- RDLabel: "Help Menu" -->
+<p>The Help menu allows access to the help or version information of the QCAD.</p>
+<h3><a name="label-41" id="label-41">Help</a></h3><!-- RDLabel: "Help" -->
+<p><img src="img/05help.png" alt="img/05help.png" /></p>
+<p>Select the Help option to open the contents of QCAD help file.</p>
+<h3><a name="label-42" id="label-42">Version</a></h3><!-- RDLabel: "Version" -->
+<p>Select the Version option to show the version information of the QCAD.</p>
+<h2><a name="label-43" id="label-43">Simulate Circuit</a></h2><!-- RDLabel: "Simulate Circuit" -->
+<p><img src="img/06run.png" alt="img/06run.png" /></p>
+<pre>You can simulate a designed circuit on QCAD.</pre>
+<p>Try "Calc" of "Calc" menu, or hit "F5" key, and QCAD simulate your circuits and show results.</p>
+<p>WARNING:</p>
+<p>The calculation of the quantum circuits requires huge memory. When the circuit has 32 lines, for example, it will use 64GB. If you try to calculate large circuits, your machine might be in trouble.</p>
+<h2><a name="label-44" id="label-44">Measurement</a></h2><!-- RDLabel: "Measurement" -->
+<pre>From Ver. 1.92, measurement gates has been available. If a circuit contains measurement gates, the "Measurement View" becomes available.</pre>
+<p><img src="img/measurement3.png" alt="img/measurement3.png" /> </p>
+<p>For example, the above circuits involves the following measured result.</p>
+<p><img src="img/measurement4.png" alt="img/measurement4.png" /> </p>
+<p>The result contains indeces, qubits' status, and the probability that the status to be measured, respectively.</p>
+<h3><a name="label-45" id="label-45">NOTE:</a></h3><!-- RDLabel: "NOTE:" -->
+<p>This measurememt DOES NOT achieve real measurement.\r
+The measurement gates on QCAD do only set "measurement flags". After the calculation, the measurement is performed.</p>
+<p>For example, the following two circuits are equivalent on QCAD.</p>
+<p><img src="img/measurement1.png" alt="img/measurement1.png" />\r
+<img src="img/measurement2.png" alt="img/measurement2.png" /></p>
+<h2><a name="label-46" id="label-46">Save Results</a></h2><!-- RDLabel: "Save Results" -->
+<dl>
+<dt><a name="label-47" id="label-47">Save Results</a></dt><!-- RDLabel: "Save Results" -->
+<dd>
+You can save the simulated results as a text file (Comma Separated Values).
+</dd>
+</dl>
+<p>The format of the exported file is as follows,</p>
+<pre>#QCAD Result file\r
+#ex) Index), (Qubits conf.), (Abs. value), (Re. part), (Im. part)\r
+#ex)      0, |00000&gt;       , 1.000       , 0.4455    , 0.23  \r
+0,|0000000&gt;, 1.000000,1.000000,0.000000\r
+1,|0000001&gt;, 0.000000,0.000000,0.000000\r
+.....\r
+127,|1111111&gt;, 0.000000,0.000000,0.000000</pre>
+<dl>
+<dt><a name="label-48" id="label-48">Save Measured Results</a></dt><!-- RDLabel: "Save Measured Results" -->
+<dd>
+If you want to save the measured results, select the "Save Results" menu on the "File" menu after choosing "Measurement view". The format of the results file is equivalent to which showed on Measurement view.
+</dd>
+</dl>
+<h2><a name="label-49" id="label-49">Known Problems</a></h2><!-- RDLabel: "Known Problems" -->
+<p>QCAD has some problems as following.</p>
+<ol>
+<li>Step-by-step execution is not available yet.</li>
+</ol>
+<h2><a name="label-50" id="label-50">About Developers</a></h2><!-- RDLabel: "About Developers" -->
+<ul>
+<li>Hiroshi Watanabe (Representative)</li>
+<li>Masaru Suzuki (Programmer)</li>
+<li>Junnosuke Yamazaki (Programmer) </li>
+</ul>
+<h2><a name="label-51" id="label-51">License</a></h2><!-- RDLabel: "License" -->
+<p>Copyright (C) 2002 - 2011 QCAD Developers Team</p>
+<p>Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:</p>
+<ol>
+<li>In any scientific publication based wholly or in part on the Software, the use of the Software must be acknowledged.</li>
+<li>Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.</li>
+<li>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. </li>
+</ol>
+<pre>THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESS OR IMPLIED\r
+WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND\r
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL  OR\r
+CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON\r
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\r
+ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</pre>
+<h2><a name="label-52" id="label-52">Acknowledgements</a></h2><!-- RDLabel: "Acknowledgements" -->
+<p>This work is supported by a grant under the youth section of Exploratory Software\r
+Project FY2002 (IPA, Japan). This software was developed at the University of Tokyo\r
+and Nagoya University.</p>
+<h2><a name="label-53" id="label-53">History</a></h2><!-- RDLabel: "History" -->
+<ul>
+<li>2011-8-3 Ver 2.00
+<ul>
+<li>Change format of helpfile from Windows help (*.hlp) to HTML help (*.chm).</li>
+<li>Change Icons.</li>
+<li>Change licence.</li>
+<li>Documentations are revised.</li>
+</ul></li>
+<li>2009-2-9 Ver 1.96
+<ul>
+<li>Bugs that Rotation and Controlled Rotation gates lost the factional part of phase were fixed.</li>
+</ul></li>
+<li>2008-10-25 Ver 1.95
+<ul>
+<li>Rotation and Controlled Rotation gates become to accept non-integer value.</li>
+<li>GUI for setting phase is implemented.</li>
+</ul></li>
+<li>2008-10-02 Ver 1.94
+<ul>
+<li>Bugs in Controlled Rotation Gate are fixed.</li>
+<li>Visualization on Result Window is optimized.</li>
+</ul></li>
+<li>2007-5-25 Ver 1.93
+<ul>
+<li>Bugs in Undo are fixed.</li>
+<li>Bugs in the form for modifying circuits are fixed.</li>
+</ul></li>
+<li>2005-10-18 Ver 1.92
+<ul>
+<li>Measurement gates become available.</li>
+<li>Bugs on shoing the help file is fixed.</li>
+</ul></li>
+<li>2005-10-06 Ver 1.91
+<ul>
+<li>A problem using resource of Windows too much was fixed.</li>
+</ul></li>
+<li>2005-07-28 Ver 1.90
+<ul>
+<li>A new function "Show Only NonZero" was implemented.</li>
+</ul></li>
+<li>2005-05-01 Ver 1.89
+<ul>
+<li>Bugs on loading file was fixed.</li>
+</ul></li>
+<li>2005-04-26 Ver 1.88
+<ul>
+<li>Bugs that Pauli Gates were ignored was fixed.</li>
+</ul></li>
+<li>2005-04-26 Ver 1.87
+<ul>
+<li>Definitions of Rotation Gates in "Quantum Computation and Quantum Information" by M. A. Nielsen and I. L. Chuang are taken.</li>
+</ul></li>
+<li>2005-04-21 Ver 1.86
+<ul>
+<li>Definitions of Z-Rotation Gates are revised.</li>
+</ul></li>
+<li>2005-04-18 Ver 1.85
+<ul>
+<li>Bugs on a Z-Rotation a Controlled Z-Rotation Gates were fixed.</li>
+</ul></li>
+<li>2005-03-17 Ver 1.84
+<ul>
+<li>Bugs on Rotation Gates were fixed.</li>
+<li>Add Z Rotation Gate.</li>
+</ul></li>
+<li>2005-03-14 Ver 1.83
+<ul>
+<li>Bugs on Pauli-Gates were fixed.</li>
+</ul></li>
+<li>2004-10-27 Ver 1.82
+<ul>
+<li>Some messages were revised.</li>
+</ul></li>
+<li>2004-09-15 Ver 1.81
+<ul>
+<li>Add scroll bar at the Result-View.</li>
+<li>Add Save function on the Result-View.</li>
+<li>Bugs on calculations were fixed.</li>
+</ul></li>
+<li>2003-05-08 Ver 1.80
+<ul>
+<li>All Gates are availavle.</li>
+<li>New views are now availavle.</li>
+<li>Bugs of View were fixed.</li>
+</ul></li>
+<li>2003-01-27 Ver 1.70
+<ul>
+<li>Bug of computation of "Controlled Rotate" is fixed.</li>
+<li>Add Not Gate.</li>
+</ul></li>
+<li>2003-01-22 Ver 1.60
+<ul>
+<li>Add "Undo" to Menu.</li>
+</ul></li>
+<li>2002-12-31 Ver 1.50beta
+<ul>
+<li>Add Simulator on QCAD.</li>
+</ul></li>
+<li>2002-06-24 Ver 1.00
+<ul>
+<li>Release First version.</li>
+</ul></li>
+</ul>
+<p><hr><div class=footer>QCAD<BR>Copyright &copy; 2002 - 2011 QCAD Developers Team. All rights reserved.<BR><a href="http://qcad.sourceforge.jp/">http://qcad.sourceforge.jp/</a></div></p>
+
+</body>
+</html>
diff --git a/htdocs/qcadhelp.rd b/htdocs/qcadhelp.rd
new file mode 100644 (file)
index 0000000..1394748
--- /dev/null
@@ -0,0 +1,439 @@
+=begin head\r
+<title>Qcad Help File</title>\r
+<META http-equiv="Content-Style-Type" content="text/css">\r
+<STYLE TYPE="text/css">\r
+<!--\r
+body {line-height: 120%;  background-color:#ffffd2; color: black}\r
+A:link { text-decoration:none; font-weight:bold; color:#161FFA }\r
+A:visited { text-decoration:none; font-weight:bold; color:#06AAFF }\r
+A:active { text-decoration:none; font-weight:bold; color:#8470FF }\r
+A:hover { font-weight:bold; color:#FF707F }\r
+H1 {padding-top:10px;text-align: center}\r
+H2 {padding-top:10px;border-top: black 1px solid;}\r
+code {padding:10px; display:block;white-space:pre;border: solid 1px #AAAAAA;}\r
+dt{font-weight:bold;}\r
+div.footer{text-align:center;color:#800000;}\r
+-->\r
+</STYLE>\r
+=end\r
+\r
+=begin\r
+=QCAD - HelpFile\r
+((:<div align=center><img src="img/qcadico48.png"></div>:))\r
+\r
+QCAD is a windows-based GUI environment of Quantum Computing Simulation, it will help you to study quantum computations. \r
+\r
+This software has following functions.\r
+\r
+(1) Graphical Designing Environment for Quantum Circuits.\r
+(2) Quantum Simulator\r
+(3) Exportable EPS and Bitmap file of circuits designed by QCAD.\r
+\r
+==Table of contents\r
+\r
+* About:\r
+  * ((<Specifications>))\r
+  * ((<Installation & Uninstallation>))\r
+* Design Circuits:\r
+  * ((<Edit Window>))\r
+  * ((<Circuit Panel>))\r
+  * ((<Available Quantum Gates>))\r
+  * ((<Save & Load>))\r
+  * ((<Export Other Format>))\r
+* Menu References:\r
+  * ((<Menu References>))\r
+* Simulator:\r
+  * ((<Simulate Circuit>))\r
+  * ((<Measurement>))\r
+  * ((<Save Results>))\r
+*Other Information:\r
+  * ((<Known Problems>))\r
+  * ((<About Developers>))\r
+  * ((<License>))\r
+  * ((<Acknowledgements>))\r
+  * ((<History>))\r
+\r
+==Specifications\r
+\r
+===Functions\r
+\r
+:GUI Environment to design quantum circuits\r
+&nbs