cengines¶
The HiQ compiler engines package.
Greedy Scheduler is a new method optimizing simulator performance not previously described. |
|
HiQ Main Engine provides all functionality of the main compiler engine. |
|
DummyBackend used for testing. |
|
FakeSimulator used only for testing. |
Module contents¶
-
class
hiq.projectq.cengines.
DummyBackend
(cluster_size, num_global)[source]¶ DummyBackend used for testing. It keeps tracks of
number of gates and swaps,
number of matrix-vector multiplications, etc.
and prints the final statistics.
-
__init__
(cluster_size, num_global)[source]¶ - Parameters
cluster_size (int) – The maximum number of qubits in fused multi-qubit gate
num_global (int) – Number of global qubits
-
is_available
(cmd)[source]¶ Default implementation of is_available: Ask the next engine whether a command is available, i.e., whether it can be executed by the next engine(s).
- Parameters
cmd (Command) – Command for which to check availability.
- Returns
True if the command can be executed.
- Raises
LastEngineException – If is_last_engine is True but is_available is not implemented.
-
class
hiq.projectq.cengines.
GreedyScheduler
(supremacy_circuit=False, num_splits=1000000, cluster_size=4)[source]¶ Greedy Scheduler is a new method optimizing simulator performance not previously described.
- Key concepts:
There are local and global qubits. If gate is acting on local qubits matrix-vector product can be calculated without access to non-local parts. To apply gate to global qubits one need to make them local, i.e. reorder qubits.
Gates are reordered into sequences called stages. A stage contains gates acting on local qubits. Inside the stage gates form subsequences called clusters. Gates from the same cluster are fused into single multi-qubit gate and this gate is simulated by single matrix-vector multiplication. Between stages qubit reordering occur.
Greedy algorithm calculates a permutation of gates and permutation of qubits which lead to minimum number of clusters in a stage and minimum number of stages during quantum circuit simulation.
Example
Shor MPI creates the main engine using Greedy Scheduler.
compilerengines = [GreedyScheduler()] simulator = SimulatorMPI(gate_fusion=True, num_local_qubits=20) # make the compiler and use the SimulatorMPI as a backend eng = HiQMainEngine(simulator, compilerengines) # In the above line HiQMainEngine can be replaced by MainEngine from # ProjectQ.
Note
Greedy Scheduler should be the last engine in the list.
-
__init__
(supremacy_circuit=False, num_splits=1000000, cluster_size=4)[source]¶ - Parameters
supremacy_circuit (bool) – If you want to use random circuits, you can specify this parameter as True. Then all last CZ gates will be ignored, because they do not affect the result of final measurement.
num_splits (int) – Number of branch splits
cluster_size (int) – Maximum number of qubits in fused multi-qubit gate
-
class
hiq.projectq.cengines.
HiQMainEngine
(backend=None, engine_list=None, verbose=False)[source]¶ HiQ Main Engine provides all functionality of the main compiler engine. It is an extension of ProjectQ MainEngine adopted for using with SimulatorMPI.
-
allocate_qureg
(n, init=0.0)[source]¶ Allocate n qubits and return them as a quantum register, which is a list of qubit objects.
- Parameters
n (int) – Number of qubits to allocate
init (complex) – Assign this value to every amplitude
- Returns
Qureg of length n, a list of n newly allocated qubits.
-
deallocate_qubit
(qubit)[source]¶ Deallocate a qubit (and sends the deallocation command down the pipeline). If the qubit was allocated as a dirty qubit, add DirtyQubitTag() to Deallocate command.
- Parameters
qubit (BasicQubit) – Qubit to deallocate.
- Raises
ValueError – Qubit already deallocated. Caller likely has a bug.
-