QGAME is a language used to describe quantum programs using the gate model. The syntax that can be parsed by QGame++ follows that used by Lee Spector's original QGAME implementation, and is also described in his soon-to-be-published book "Automatic Quantum Computer Programming: A Genetic Programming Approach" and various material found on Lee's homepage at http://hampshire.edu/lspector . I will give a brief description of the syntax here.
- Note:
- The current version of the parser is line-oriented, meaning that each instruction must be in a single line. The parser currently also is not very robust when it comes to extra whitespace and so on. Note that libqgame++ does not care for how its QProgram object is created, and you might write your own parser that spills out QInstruction objects, or create a QProgram any way you want. This language description therefore is used mostly to describe what to feed into the command line client 'qgame' rather than how to access libqgame++ itself.
The parameters needed for program execution can be supplied on the command line, or specified in the QGAME program file. For the latter, parameter lines are started with a colon, followed by the parameter's name and a space-separated list of values. Note that parameters given on the command line override those found in the text.
- :num-qubits <num> defines the number of qubits the system should use for executing the program.
- :cases <case_1> <case_2> ... <case_n> supplies a number of test cases used for program evaluation if qgame is run in evaluation mode. A test case specifies the truth table and the desired result for this run. '0101-1' therefore means that the oracle's truth table is 0101, and one wants to measure a 1. The probability for measuring the desired result in each test case will define the evaluation result.
- :threshold <t> defines the error threshold to be used when evaluating the program. If the error probability of measuring the desired result is below that threshold, the test run is considered to be successful. A common value used here is 0.48.
- :final-measurement-qubits <q1> <q2> ... <qn> specifies the list of qubits that are to be measured after execution of the program in order to achieve the desired result given for the current test case. The least significant qubit is listed last. The resulting probability is computed across all possible branches caused by intermediate measurements.
After specifying parameters, a list of QGAME instructions should follow, each instruction in a single line (no linebreaks). In addition, you might have comment lines started by a '#'. Note that QGame++ is based on a LISP program and the syntax therefore looks pretty LISPish (i.e. there are a lot of brackets...).
Following is a list of all QGAME instructions that define gates. Note that whenever a qubit list is specified, a list of integers is expected, with the least significant qubit last.
- (QNOT <q>) applies a quantum NOT gate to the specified qubit
- (CNOT <control> <target>) applies a quantum controlled NOT gate to the specified control and target qubits
- (SRN <q>) applies a quantum square-root-of-NOT gate to the specified qubit
- (NAND <in1> <in2> <out>) applies a quantum NAND gate to the specified input and output qubits
- (HADAMARD <q>) applies a Hadamard gate to the specified qubit
- (U-THETA <q> <theta>) applies a rotation gate with the specified (real-valued) angle theta to the specified qubit
- (CPHASE-OLD <control> <target> <alpha>): one version of a controlled phase gate -- see Quantum Gates for the matrix
- (CPHASE <control> <target> <alpha>): another (probably preferable) version of a controlled phase gate -- see Quantum Gates for the matrix
- (U2 <q> <phi> <theta> <psi> <alpha>): a general rotation gate for a single qubit with 4 real-valued parameters -- see Quantum Gates for the matrix
- (SWAP <q1> <q2>) applies a gate that swaps the amplitudes of the two specified qubits
- (MATRIX-GATE #2A((row1)(row2)...(rown)) (history)): This specifies a general matrix gate. The matrix is given as a LISP-style 2D array. Each row contains space-separated real values. Note that although a matrix technically can contain complex values, this is not supported by the current version of the parser (you might create QMatrixGate objects containing complex values though, if you use libqgame++ in your own program or create a QProgram object by other means). The specified matrix must be unitary and be of size 2^n X 2^n, with n being the number of qubits in the system. The gate is applied to the complete quantum register. (history) is an optional parameter that is not currently used by QGame++.
- (ORACLE ORACLE-TT <q1> <q2> ... <qn> <out>): calls the oracle on the specified input qubits (specified as "q"s above) and the specified output qubit. The input qubits are listed most significant first. ORACLE-TT might appear as a literal symbol in the call -- this will be replaced with the oracle's truth table before execution. Alternatively, you might specify a fixed truth table as a space-separated, bracket-enclosed list specifying the right-hand side of the truth table.
- (LIMITED-ORACLE ORACLE-TT <max-calls> <q1> <q2> ... <qn> <out>): like ORACLE but with one additional argument, max-calls, which should be a positive integer. If the provided number of oracle calls has already been made by the time this instruction is executed then it will have no effect.
The following instructions do not specify gates, but rather influence the control flow of the program or help with debugging.
- (MEASURE <q>) <1-branch> (END) <0-branch> (END): causes a measurement-based branch in the execution of the quantum program (causing the creation of a new QSys object). In one branch the state will be collapsed as if "1" was read from the specified qubit, the 1-branch code will be executed and the 0-branch code will be skipped. In the other branch the state will be collapsed as if "0" was read from the specified qubit, the 0-branch code will be executed and the 1-branch code will be skipped. Measurement structures can be nested within the branches of other measurement structures. If there is no second END then execution in the 1 case terminates after execution of the 1-branch. If there is no first END then there is no 0-branch. Unmatched ENDs are ignored.
- (HALT): causes the executing quantum system to halt execution (to execute no further instructions)
- (PRINTAMPS): Prints the current state of the executing quantum system to STDOUT. This includes the measurement history, the current contents of the quantum register, and the probabilities for each amplitude.
- (INSP): This instruction only exists for compatibility with Lee Spector's LISP version of QGAME and does nothing in QGame++.
Generated on Sat Apr 3 18:42:28 2004 for QGame++ by
1.3.5