-
Notifications
You must be signed in to change notification settings - Fork 4
Initial register management implementation #176
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
Merged
rturrado
merged 16 commits into
develop
from
167-initial-register-management-implementation
May 8, 2024
Merged
Changes from 4 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
b1390bb
Merge branch '152-basic-implementation-mapper' into 167-initial-regis…
rturrado 15a699c
WIP.
rturrado 90dda12
Merge branch 'develop' into 167-initial-register-management-implement…
rturrado b7e4900
Getting there.
rturrado 64805c7
Fix all tests.
rturrado e0241ac
Reformat all code.
rturrado 5dbfc77
Add reindexer/qubit_reindexer.py.
rturrado c95643c
Run poetry black formatter.
rturrado 4d05202
Run poetry isort.
rturrado cae753d
Trying to fix mapping.py errors.
rturrado 1346a6d
Add TODO.
rturrado 8e21d37
Add reindex_circuit.
rturrado bdd208f
Add _QubitReindexer doc.
rturrado 3e8803a
Remove mapping from RegisterManager.
rturrado 3dd13dd
Merge branch 'develop' into 167-initial-register-management-implement…
rturrado 1799376
Changed replacement_gates_4 so that we test all the _QubitReindexer v…
rturrado 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,30 +1,31 @@ | ||
import numpy as np | ||
|
||
from opensquirrel.circuit import Circuit | ||
from opensquirrel.squirrel_ir import Comment, Gate, SquirrelIR, SquirrelIRVisitor | ||
from opensquirrel.utils.matrix_expander import get_matrix | ||
|
||
|
||
class _CircuitMatrixCalculator(SquirrelIRVisitor): | ||
def __init__(self, number_of_qubits): | ||
self.number_of_qubits = number_of_qubits | ||
self.matrix = np.eye(1 << self.number_of_qubits, dtype=np.complex128) | ||
def __init__(self, qubit_register_size): | ||
self.qubit_register_size = qubit_register_size | ||
self.matrix = np.eye(1 << self.qubit_register_size, dtype=np.complex128) | ||
|
||
def visit_gate(self, gate: Gate): | ||
big_matrix = get_matrix(gate, number_of_qubits=self.number_of_qubits) | ||
big_matrix = get_matrix(gate, qubit_register_size=self.qubit_register_size) | ||
self.matrix = big_matrix @ self.matrix | ||
|
||
def visit_comment(self, comment: Comment): | ||
pass | ||
|
||
|
||
def get_circuit_matrix(squirrel_ir: SquirrelIR): | ||
def get_circuit_matrix(circuit: Circuit): | ||
""" | ||
Compute the Numpy unitary matrix corresponding to the circuit. | ||
The size of this matrix grows exponentially with the number of qubits. | ||
""" | ||
|
||
impl = _CircuitMatrixCalculator(squirrel_ir.number_of_qubits) | ||
impl = _CircuitMatrixCalculator(circuit.qubit_register_size) | ||
|
||
squirrel_ir.accept(impl) | ||
circuit.squirrel_ir.accept(impl) | ||
|
||
return impl.matrix |
This file contains hidden or 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 hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.