-
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.
Completed QASM interface for all gates and tested basic funcs. --------- Signed-off-by: burgholzer <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Lukas Burgholzer <[email protected]>
- Loading branch information
1 parent
425e102
commit c1dee1a
Showing
13 changed files
with
251 additions
and
66 deletions.
There are no files selected for viewing
Binary file not shown.
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from __future__ import annotations | ||
|
||
from .classic_register import ClassicRegister | ||
from .quantum_register import QuantumRegister | ||
|
||
__all__ = ["ClassicRegister", "QuantumRegister"] |
40 changes: 40 additions & 0 deletions
40
src/mqt/qudits/quantum_circuit/components/classic_register.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,40 @@ | ||
from __future__ import annotations | ||
|
||
|
||
class ClassicRegister: | ||
@classmethod | ||
def from_map(cls, sitemap: dict) -> list[ClassicRegister]: | ||
registers_map = {} | ||
|
||
for creg_with_index, line_info in sitemap.items(): | ||
reg_name, inreg_line_index = creg_with_index | ||
if reg_name not in registers_map: | ||
registers_map[reg_name] = [{inreg_line_index: creg_with_index[0]}, line_info] | ||
else: | ||
registers_map[reg_name][0][inreg_line_index] = line_info | ||
|
||
registers_from_qasm = [] | ||
for label, data in registers_map.items(): | ||
temp = ClassicRegister(label, len(data[0])) | ||
temp.local_sitemap = data[0] | ||
registers_from_qasm.append(temp) | ||
|
||
return registers_from_qasm | ||
|
||
def __init__(self, name, size) -> None: | ||
""" | ||
Class for classical register memories | ||
""" | ||
self.label = name | ||
self.size = size | ||
self.local_sitemap = {} | ||
|
||
def __qasm__(self): | ||
return "creg " + self.label + " [" + str(self.size) + "]" + ";" | ||
|
||
def __getitem__(self, key): | ||
if isinstance(key, slice): | ||
start, stop = key.start, key.stop | ||
return [self.local_sitemap[i] for i in range(start, stop)] | ||
|
||
return self.local_sitemap[key] |
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.