-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compiler Top-Down Integration #49
Merged
Changes from all commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
000538e
removed test file of obsolete pass
KevinMTO 5613167
Merge branch 'main' of github.com:cda-tum/mqt-qudits into two_dit
KevinMTO 98a356b
crot modification
KevinMTO e10633d
integration of two body compiler
KevinMTO eb765dc
Merge branch 'main' of github.com:cda-tum/mqt-qudits into two_dit
KevinMTO 1c6dfdd
integration of compiler
KevinMTO 7dc2cd3
bug fix of matrix factory
KevinMTO 184e04a
Merge branch 'main' of github.com:cda-tum/mqt-qudits into two_dit
KevinMTO 756c6d7
Merge branch 'main' of github.com:cda-tum/mqt-qudits into two_dit
KevinMTO 8a803b7
testing improved for full stack compiler and simulator
KevinMTO f22aa2b
🎨 pre-commit fixes
pre-commit-ci[bot] c8cd19e
small codeql correction
KevinMTO 250da67
fix to test and typing
KevinMTO 94e6216
test fix state preparation
KevinMTO 39bf138
merge
KevinMTO c11f390
🎨 pre-commit fixes
pre-commit-ci[bot] ffea92b
fix interacting test
KevinMTO 4c77ac3
Merge branch 'two_dit' of github.com:cda-tum/mqt-qudits into two_dit
KevinMTO b996d38
change permutation of state
KevinMTO f3e8e08
🎨 pre-commit fixes
pre-commit-ci[bot] 09049ee
fix test
KevinMTO 1290348
Merge branch 'two_dit' of github.com:cda-tum/mqt-qudits into two_dit
KevinMTO c998585
removed test as test
KevinMTO cdc9362
🎨 pre-commit fixes
pre-commit-ci[bot] 0ab8f46
multiplicatino fix
KevinMTO 17197c1
Merge branch 'two_dit' of github.com:cda-tum/mqt-qudits into two_dit
KevinMTO 15aab98
🎨 pre-commit fixes
pre-commit-ci[bot] 086e8e5
multiplicatino fix
KevinMTO f5eed92
multiplicatino fix
KevinMTO 65baa1d
🎨 pre-commit fixes
pre-commit-ci[bot] 14e5955
update to workflow
KevinMTO 10da2e6
update to workflow
KevinMTO 5c0719e
🎨 pre-commit fixes
pre-commit-ci[bot] 46ce11f
overcome @= precommit change
KevinMTO 077d613
overcome @= precommit change
KevinMTO 12f245e
🎨 pre-commit fixes
pre-commit-ci[bot] 03d7fc1
fix toml
KevinMTO c7f881e
Merge branch 'two_dit' of github.com:cda-tum/mqt-qudits into two_dit
KevinMTO 9a393ed
🎨 pre-commit fixes
pre-commit-ci[bot] 75d2351
fix toml
KevinMTO 670f4f2
Merge branch 'two_dit' of github.com:cda-tum/mqt-qudits into two_dit
KevinMTO File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check notice
Code scanning / CodeQL
Mismatch between signature and use of an overridden method Note