Skip to content
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

feature: added controlled-sqrt-not gate #297

Merged
merged 6 commits into from
Jan 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions src/braket/circuits/gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,51 @@ def cphaseshift10(control: QubitInput, target: QubitInput, angle: float) -> Inst
Gate.register_gate(CPhaseShift10)


class CV(Gate):
"""Controlled Sqrt of NOT gate."""

def __init__(self):
super().__init__(qubit_count=None, ascii_symbols=["C", "V"])

def to_ir(self, target: QubitSet):
return ir.CV.construct(control=target[0], target=target[1])

def to_matrix(self) -> np.ndarray:
return np.array(
[
[1.0, 0.0, 0.0, 0.0],
[0.0, 1.0, 0.0, 0.0],
[0.0, 0.0, 0.5 + 0.5j, 0.5 - 0.5j], # if the control bit, then apply the V gate
[0.0, 0.0, 0.5 - 0.5j, 0.5 + 0.5j], # which is the sqrt(NOT) gate.
],
dtype=complex,
)

@staticmethod
def fixed_qubit_count() -> int:
return 2

@staticmethod
@circuit.subroutine(register=True)
def cv(control: QubitInput, target: QubitInput) -> Instruction:
"""Registers this function into the circuit class.

Args:
control (Qubit or int): Control qubit index.
target (Qubit or int): Target qubit index.

Returns:
Instruction: CV instruction.

Examples:
>>> circ = Circuit().cv(0, 1)
"""
return Instruction(CV(), target=[control, target])


Gate.register_gate(CV)


class CY(Gate):
"""Controlled Pauli-Y gate."""

Expand Down
1 change: 1 addition & 0 deletions test/unit_tests/braket/circuits/test_gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
(Gate.Ry, "ry", ir.Ry, [SingleTarget, Angle], {}),
(Gate.Rz, "rz", ir.Rz, [SingleTarget, Angle], {}),
(Gate.CNot, "cnot", ir.CNot, [SingleTarget, SingleControl], {}),
(Gate.CV, "cv", ir.CV, [SingleTarget, SingleControl], {}),
(Gate.CCNot, "ccnot", ir.CCNot, [SingleTarget, DoubleControl], {}),
(Gate.Swap, "swap", ir.Swap, [DoubleTarget], {}),
(Gate.CSwap, "cswap", ir.CSwap, [SingleControl, DoubleTarget], {}),
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ commands =
deps =
# If you need to test on a certain branch, add @<branch-name> after .git
git+https://github.com/aws/amazon-braket-schemas-python.git
git+https://github.com/aws/amazon-braket-default-simulator-python.git
git+https://github.com/aws/amazon-braket-default-simulator-python.git