Usage
Compile
The isQ compiler receives the isQ source file as input, and the instruction format is as follows:
isqc compile [options] <Input>
options:
--emit <FORMAT>
: output content format, format value can bemlir, mlirqir, llvm, mlir-optimized, binary, out
[default:out
]-o, --output <OUTFILE>
: output file-O, --opt-level <OPT_LEVEL>
: llvm opt-level such as-O1, -O2, -O3
etc.--target <TARGET_IR>
: target ir, now supportqir, open-qasm3, qcis
[default:qir
]--qcis-config <MAPPING_CONFIG_FILE>
: qcis mapping config file-I, --inc-path <INC_PATH>
: library path of isQ used in the source code, a default path is$ISQ_ROOT/lib
-i <INT>
: int type paramter, which is used when compiled to qcis-d <DOUBLE>
double type paramter, which is used when compiled to qcis
compile to qir
QIR is a new Microsoft-developed intermediate representation for quantum programs. Users can compile source file to qir using the following command
or may compile to intermediate results, such as mlir
compile to qcis
QCIS is specially tailored for the superconducting quantum hardware at the University of Science and Technology of China. Users can compile source file to qcis using the following command
Qcis instructions can run on real superconducting hardware, so isQ compiler provides qubit-mapping function. If want to use this feature, users should feed a configuration file mapping_config_file
. The file is usually in JSON format, and needs to include the following fields:
{
// required
"qbit_num": 12, // qubit number on hardware
"topo": [[1,2],[2,3],[3,4],[4,5],[5,6],[6,7],[7,8],[8,9],[9,10],[10,11],[11,12]], // topology of hardware
// option
"init_map": "simulated_annealing" // the way to get init mapping
}
--qcis config
QCIS hardware does not support feedback control, so there are some restrictions on the usage of isQ
- can not use reset
- can not print
- can not use measurement results as right value, like assignment, condition
isQ supports compiling with parameters. When compiling to QCIS, users need pass parameter values in order to generate a definite circuit.
compile using the following commandSimulate
The simulator of isQ provides the simulation of qir
or qcis
. The instruction format is as follows
isqc simulate [options] <Input>
options:
--shots <NUM>
: simulate times, default is 1--debug
: use debug mod and get theprint
result--cuda <NUM>
: use gpu,NUM
is the number of qubits to be simulated-i <INT>
: int type paramter-d <DOUBLE>
: double type paramter--qcis
: simulate qcis--qn <QN>
: maximum qubit number, default is 25--probs
: show the probabilites of measurement results
simulate qir
The input must be a .so file generated by compiler, and can use as follows:
# simulate in cpu
isqc simulate ./source.so
# simulate in gpu
isqc simulate --cuda 10 ./source.so
# run 10 times and use debug mod
isqc simulate --shots 10 --debug ./source.so
isQ supports compiling with parameters and passing values at runtime. The following program is compiled as qir
with parameters, and users can pass values during simulation through -i, -d
. isQ will gather values and generate int and double arrays (can be empty).
simulate qcis
isQ simulator can also simulate qcis
through --qcis
. The input must be a .qcis file and isQ will check the format of the QCIS instructions.
result
The output is the statistical result of measurement in source.isq, like {"00": 4, "11": 6}
. The results of all measurement operations will be added to the result string, even if it is an assignment operation like int a = M(q);
import std;
procedure main(){
qbit q[2];
H(q[0]);
ctrl X(q[0],q[1]);
int a = M(q[0]);
int b = M(q[1]);
print a - b;
}
The result of above isQ program can be {"11": 47, "00": 53}
. In this program, there is a print operation, the result of this operation will not output until using debug mode through --debug
. In debug mode, print result of each simulation will output to stderr, the format like {ith simulate print: 0}
. When the shot_num is large, there will be many print result. It is suitable that redirect the stderr to a file. Taking the above program as an example:
output
res.txtshow possibilites
Instead of repeating the simulation with many shots, isQ also supports generating the theory possibilities of measurement results. This can be done with the --probs
argument. Then, isQ prints the possibilities of measurement results in an array. The index of the array is the measurement result, whereas the earlier measured qubit is the higher bit. Note that the measured qubits must be global. The reason is that local qubits will be deallocated at the end of execution, so the simulator cannot find out the possibilities.
The following program, prob.isq
, is a simple example.
q[1]
and q[0]
. The measurement results have four combinations:
Measurement result | q[1] | q[0] | Possibility |
---|---|---|---|
00 | 0 | 0 | 0 |
01 | 0 | 1 | 0 |
10 | 1 | 0 | 0.5 |
11 | 1 | 1 | 0.5 |
Simulate the previous program with command
The result isRun
Users can use isQ’s run
command to compile and simulate quantum programs (compile to qir
)
options
--shots <NUM>
: simulate times, default is 1--debug
: use debug mod and get theprint
result--qn <QN>
: maximum qubit number, default is 25--probs
: show the probabilites of measurement results
isQ will compile source file to qir
first, and then simulate. The options will be forwarded to isqc simulate
.