-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
517 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
qutip\_qip.decompose package | ||
============================ | ||
|
||
Submodules | ||
---------- | ||
|
||
qutip\_qip.decompose.single\_qubit\_gate module | ||
----------------------------------------------- | ||
|
||
.. automodule:: qutip_qip.decompose.single_qubit_gate | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
Module contents | ||
--------------- | ||
|
||
.. automodule:: qutip_qip.decompose | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: |
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 @@ | ||
from .single_qubit_gate import * |
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,39 @@ | ||
import numpy as np | ||
import cmath | ||
|
||
from qutip import Qobj | ||
|
||
class MethodError(Exception): | ||
"""When invalid method is chosen, this error is raised. | ||
""" | ||
pass | ||
|
||
class GateError(Exception): | ||
"""When chosen method cannot be applied to the input gate, this error | ||
is raised. | ||
""" | ||
pass | ||
|
||
|
||
def check_gate(gate, num_qubits): | ||
"""Verifies input is a valid quantum gate. | ||
Parameters | ||
---------- | ||
gate : :class:`qutip.Qobj` | ||
The matrix that's supposed to be decomposed should be a Qobj. | ||
num_qubits: | ||
Number of qubits in the circuit. | ||
Raises | ||
------ | ||
TypeError | ||
If the gate is not a Qobj. | ||
ValueError | ||
If the gate is not a unitary operator on qubits. | ||
""" | ||
if not isinstance(gate, Qobj): | ||
raise TypeError("The input matrix is not a Qobj.") | ||
if not gate.check_isunitary(): | ||
raise ValueError("Input is not unitary.") | ||
if gate.dims != [[2] * num_qubits] * 2: | ||
raise ValueError(f"Input is not a unitary on {num_qubits} qubits.") |
Oops, something went wrong.