-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into LessThanGateWriteup
- Loading branch information
Showing
11 changed files
with
218 additions
and
8 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
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
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
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,64 @@ | ||
# Copyright 2023 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from functools import cached_property | ||
from typing import Dict, Tuple, TYPE_CHECKING | ||
|
||
import numpy as np | ||
import quimb.tensor as qtn | ||
from attrs import frozen | ||
|
||
from qualtran import Bloq, Signature, SoquetT | ||
|
||
if TYPE_CHECKING: | ||
import cirq | ||
|
||
from qualtran.cirq_interop import CirqQuregT | ||
from qualtran.simulation.classical_sim import ClassicalValT | ||
|
||
_PAULIY = np.array([[0, -1j], [1j, 0]], dtype=np.complex128) | ||
|
||
|
||
@frozen | ||
class YGate(Bloq): | ||
"""The Pauli Y gate. | ||
This causes a bit flip (with a complex phase): Y|0> = 1j|1>, Y|1> = -1j|0> | ||
""" | ||
|
||
@cached_property | ||
def signature(self) -> 'Signature': | ||
return Signature.build(q=1) | ||
|
||
def add_my_tensors( | ||
self, | ||
tn: qtn.TensorNetwork, | ||
binst, | ||
*, | ||
incoming: Dict[str, SoquetT], | ||
outgoing: Dict[str, SoquetT], | ||
): | ||
tn.add( | ||
qtn.Tensor( | ||
data=_PAULIY, inds=(outgoing['q'], incoming['q']), tags=[self.short_name(), binst] | ||
) | ||
) | ||
|
||
def as_cirq_op( | ||
self, qubit_manager: 'cirq.QubitManager', q: 'CirqQuregT' | ||
) -> Tuple['cirq.Operation', Dict[str, 'CirqQuregT']]: | ||
import cirq | ||
|
||
(q,) = q | ||
return cirq.Y(q), {'q': [q]} |
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 @@ | ||
# Copyright 2023 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import cirq | ||
import numpy as np | ||
|
||
from qualtran import BloqBuilder | ||
from qualtran.bloqs.basic_gates import MinusState, PlusState, YGate | ||
|
||
|
||
def test_to_cirq(): | ||
bb = BloqBuilder() | ||
q = bb.add(PlusState()) | ||
q = bb.add(YGate(), q=q) | ||
cbloq = bb.finalize(q=q) | ||
circuit, _ = cbloq.to_cirq_circuit() | ||
cirq.testing.assert_has_diagram(circuit, "_c(0): ───H───Y───") | ||
vec1 = cbloq.tensor_contract() | ||
vec2 = cirq.final_state_vector(circuit) | ||
np.testing.assert_allclose(vec1, vec2) | ||
|
||
bb = BloqBuilder() | ||
q = bb.add(MinusState()) | ||
q = bb.add(YGate(), q=q) | ||
cbloq = bb.finalize(q=q) | ||
circuit, _ = cbloq.to_cirq_circuit() | ||
cirq.testing.assert_has_diagram(circuit, "_c(0): ───[ _c(0): ───X───H─── ]───Y───") | ||
vec1 = cbloq.tensor_contract() | ||
vec2 = cirq.final_state_vector(circuit) | ||
np.testing.assert_allclose(vec1, vec2) |