-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Description This PR integrates the compiler in fully automated fashion from the circuit to the simulations results. - Introduced gate and circuit compilation. - Integrated fully mixed-dimensional, two-body gate compilation through compiler and ansatz optimization. - Introduced a lookahead strategy and data structure (Lanes) and a resynthesis tool for local gate compilation. - Integrated Givens Z rotation compression and removal. - Introduced a layer of abstraction using "blocks": crtot, crz, and pswap objects. - Modified matrix multiplications. - Explored sparsification algorithms. - Saved mappings and re-encoding of simulation results. - Fixed MS, LS, Perm gates, and matrix factory. - Fixed energy level graph for fake backends. ## Checklist: - [X] The pull request only contains commits that are related to it. - [X] I have added appropriate tests and documentation. - [ ] I have made sure that all CI jobs on GitHub pass. - [X] The pull request follows the project's style guidelines. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
a65af54
commit a285729
Showing
66 changed files
with
3,084 additions
and
693 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,20 @@ | ||
from __future__ import annotations | ||
|
||
from abc import ABC, abstractmethod | ||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from mqt.qudits.quantum_circuit import QuantumCircuit | ||
from mqt.qudits.quantum_circuit.gate import Gate | ||
|
||
|
||
class CompilerPass(ABC): | ||
def __init__(self, backend, **kwargs) -> None: | ||
self.backend = backend | ||
|
||
def transpile_gate(self, gate: Gate) -> list[Gate]: | ||
pass | ||
|
||
@abstractmethod | ||
def transpile(self, circuit): | ||
def transpile(self, circuit: QuantumCircuit) -> QuantumCircuit: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
from __future__ import annotations | ||
|
||
from ..core.lanes import Lanes | ||
from ..quantum_circuit.components.extensions.gate_types import GateTypes | ||
from .naive_local_resynth import NaiveLocResynthOptPass | ||
from .onedit import LogLocQRPass, PhyLocAdaPass, PhyLocQRPass, ZPropagationOptPass, ZRemovalOptPass | ||
from .twodit import LogEntQRCEXPass | ||
from .twodit.entanglement_qr.phy_ent_qr_cex_decomp import PhyEntQRCEXPass | ||
|
||
|
||
class QuditCompiler: | ||
passes_enabled = { | ||
"PhyLocQRPass": PhyLocQRPass, | ||
"PhyLocAdaPass": PhyLocAdaPass, | ||
"LocQRPass": PhyLocQRPass, | ||
"LocAdaPass": PhyLocAdaPass, | ||
"LogLocQRPass": LogLocQRPass, | ||
"ZPropagationOptPass": ZPropagationOptPass, | ||
"ZRemovalOptPass": ZRemovalOptPass, | ||
"LogEntQRCEXPass": LogEntQRCEXPass, | ||
"PhyEntQRCEXPass": PhyEntQRCEXPass, | ||
"NaiveLocResynthOptPass": NaiveLocResynthOptPass, | ||
} | ||
|
||
def __init__(self) -> None: | ||
pass | ||
|
||
def compile(self, backend, circuit, passes_names): | ||
passes_dict = {} | ||
new_instr = [] | ||
# Instantiate and execute created classes | ||
for compiler_pass in passes_names: | ||
compiler_pass = self.passes_enabled[compiler_pass] | ||
decomposition = compiler_pass(backend) | ||
if "Loc" in str(compiler_pass): | ||
passes_dict[GateTypes.SINGLE] = decomposition | ||
elif "Ent" in str(compiler_pass): | ||
passes_dict[GateTypes.TWO] = decomposition | ||
elif "Multi" in str(compiler_pass): | ||
passes_dict[GateTypes.MULTI] = decomposition | ||
for gate in circuit.instructions: | ||
decomposer = passes_dict.get(gate.gate_type) | ||
new_instructions = decomposer.transpile_gate(gate) | ||
new_instr.extend(new_instructions) | ||
|
||
circuit.set_instructions(new_instr) | ||
circuit.set_mapping([graph.log_phy_map for graph in backend.energy_level_graphs]) | ||
|
||
return circuit | ||
|
||
def compile_O0(self, backend, circuit): | ||
passes = ["PhyLocQRPass", "PhyEntQRCEXPass"] | ||
compiled = self.compile(backend, circuit, passes) | ||
|
||
mappings = [] | ||
for i, graph in enumerate(backend.energy_level_graphs): | ||
mappings.append([lev for lev in graph.log_phy_map if lev < circuit.dimensions[i]]) | ||
compiled.set_mapping(mappings) | ||
return compiled | ||
|
||
def compile_O1(self, backend, circuit): | ||
phyloc = PhyLocAdaPass(backend) | ||
phyent = PhyEntQRCEXPass(backend) | ||
|
||
lanes = Lanes(circuit) | ||
new_instructions = [] | ||
for gate in circuit.instructions: | ||
if gate.gate_type is GateTypes.SINGLE: | ||
ins = phyloc.transpile_gate(gate, lanes.next_is_local(gate)) | ||
new_instructions.extend(ins) | ||
else: | ||
ins = phyent.transpile_gate(gate) | ||
new_instructions.extend(ins) | ||
transpiled_circuit = circuit.copy() | ||
mappings = [] | ||
for i, graph in enumerate(backend.energy_level_graphs): | ||
mappings.append([lev for lev in graph.log_phy_map if lev < circuit.dimensions[i]]) | ||
transpiled_circuit.set_mapping(mappings) | ||
return transpiled_circuit.set_instructions(new_instructions) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from __future__ import annotations | ||
|
||
from mqt.qudits.compiler.naive_local_resynth.local_resynth import NaiveLocResynthOptPass | ||
|
||
__all__ = [ | ||
"NaiveLocResynthOptPass", | ||
] |
46 changes: 46 additions & 0 deletions
46
src/mqt/qudits/compiler/naive_local_resynth/local_resynth.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from __future__ import annotations | ||
|
||
from typing import NoReturn | ||
|
||
import numpy as np | ||
|
||
from mqt.qudits.compiler import CompilerPass | ||
from mqt.qudits.core.lanes import Lanes | ||
from mqt.qudits.quantum_circuit.components.extensions.gate_types import GateTypes | ||
from mqt.qudits.quantum_circuit.gates import CustomOne | ||
|
||
|
||
class NaiveLocResynthOptPass(CompilerPass): | ||
def __init__(self, backend) -> None: | ||
super().__init__(backend) | ||
|
||
def transpile_gate(self, gate) -> NoReturn: | ||
raise NotImplementedError | ||
|
||
def transpile(self, circuit): | ||
self.circuit = circuit | ||
self.lanes = Lanes(self.circuit) | ||
|
||
for line in sorted(self.lanes.index_dict.keys()): | ||
grouped_line = self.lanes.find_consecutive_singles(self.lanes.index_dict[line]) | ||
new_line = [] | ||
for group in grouped_line[line]: | ||
if group[0][1].gate_type == GateTypes.SINGLE: | ||
matrix = np.identity(self.circuit.dimensions[line]) | ||
for gate_tuple in group: | ||
gate = gate_tuple[1] | ||
gm = gate.to_matrix() | ||
matrix = gm @ matrix | ||
new_line.append(( | ||
group[0][0], | ||
CustomOne(self.circuit, "CUm", line, matrix, self.circuit.dimensions[line]), | ||
)) | ||
else: | ||
new_line.append(group[0]) | ||
|
||
self.lanes.index_dict[line] = new_line | ||
|
||
new_instructions = self.lanes.extract_instructions() | ||
|
||
transpiled_circuit = self.circuit.copy() | ||
return transpiled_circuit.set_instructions(new_instructions) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
src/mqt/qudits/compiler/onedit/local_phases_transpilation/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
from __future__ import annotations | ||
|
||
from .propagate_virtrz import ZPropagationPass | ||
from .remove_phase_rotations import ZRemovalPass | ||
from .propagate_virtrz import ZPropagationOptPass | ||
from .remove_phase_rotations import ZRemovalOptPass | ||
|
||
__all__ = [ | ||
"ZPropagationPass", | ||
"ZRemovalPass", | ||
"ZPropagationOptPass", | ||
"ZRemovalOptPass", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.