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

Add decomposition for CCZ gate and IonQTargetGateset when qubits are all-to-all connected #6095

Merged
merged 21 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
aa8077f
Add all-to-all decomposition for CCZ gate
yinghui-hu May 16, 2023
d5f8c98
Fix format check and type check
yinghui-hu May 16, 2023
9555f31
Revert type check change
yinghui-hu May 16, 2023
219c710
Ignore type check for `global_phase`
yinghui-hu May 16, 2023
e31bc96
Expect test_custom_value_not_implemented to pass
yinghui-hu May 16, 2023
1d85158
Sync test_custom_value_not_implemented
yinghui-hu May 16, 2023
a89bf4c
Merge branch 'quantumlib:master' into all_connectivity_decompose
yinghui-hu May 16, 2023
397b9a7
Merge branch 'quantumlib:master' into all_connectivity_decompose
yinghui-hu May 23, 2023
e12eda1
IonQTargetGateset._decompose_multi_qubit_operation
yinghui-hu May 23, 2023
79f9c3a
Fix format and type check
yinghui-hu May 23, 2023
cf3c640
Fix type for input `qubits`
yinghui-hu May 23, 2023
eea47ce
Merge branch 'quantumlib:master' into all_connectivity_decompose
yinghui-hu Jun 2, 2023
b4ca8d7
Add test for ValueError
yinghui-hu Jun 2, 2023
f3bf72d
Merge branch 'master' into all_connectivity_decompose
yinghui-hu Jul 19, 2023
8c5afe7
Resolve comments
yinghui-hu Jul 19, 2023
4d835d7
Add a new line after summary line and before description
yinghui-hu Jul 19, 2023
6a1f140
Fix format, type and lint
yinghui-hu Jul 19, 2023
02c49a0
Ignore type check
yinghui-hu Jul 19, 2023
d31fc77
Merge branch 'master' into all_connectivity_decompose
yinghui-hu Jul 21, 2023
210f720
Merge branch 'master' into all_connectivity_decompose
yinghui-hu Jul 27, 2023
ca5b113
Merge branch 'master' into all_connectivity_decompose
yinghui-hu Aug 6, 2023
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
43 changes: 34 additions & 9 deletions cirq-core/cirq/ops/three_qubit_gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,15 @@ def _pauli_expansion_(self) -> value.LinearDict[str]:
}
)

def _decompose_(self, qubits):
"""An adjacency-respecting decomposition.
def _decompose_(self, qubits, all_to_all_connect: Optional[bool] = None):
"""If qubits are all-to-all connected, e.g. qubits in the same ion trap,
the decomposition will be:
0: ──────────────@──────────────────@───@───p──────@───
│ │ │ │
1: ───@──────────┼───────@───p──────┼───X───p^-1───X───
│ │ │ │
2: ───X───p^-1───X───p───X───p^-1───X───p──────────────
Otherwise the adjacency-respecting decomposition will be returned:

0: ───p───@──────────────@───────@──────────@──────────
│ │ │ │
Expand All @@ -110,26 +117,44 @@ def _decompose_(self, qubits):
"""
a, b, c = qubits

# Hacky magic: avoid the non-adjacent edge.
if hasattr(b, 'is_adjacent'):
if not b.is_adjacent(a):
b, c = c, b
elif not b.is_adjacent(c):
a, b = b, a
if not all_to_all_connect:
# Hacky magic: avoid the non-adjacent edge.
if hasattr(b, 'is_adjacent'):
if not b.is_adjacent(a):
b, c = c, b
elif not b.is_adjacent(c):
a, b = b, a

p = common_gates.T**self._exponent
sweep_abc = [common_gates.CNOT(a, b), common_gates.CNOT(b, c)]
global_phase = 1j ** (2 * self.global_shift * self._exponent)
global_phase = (
complex(global_phase)
if protocols.is_parameterized(global_phase) and global_phase.is_complex
if protocols.is_parameterized(global_phase) and global_phase.is_complex # type: ignore
else global_phase
)
global_phase_operation = (
[global_phase_op.global_phase_operation(global_phase)]
if protocols.is_parameterized(global_phase) or abs(global_phase - 1.0) > 0
else []
)

if all_to_all_connect:
return global_phase_operation + [
common_gates.CNOT(b, c),
p(c) ** -1,
common_gates.CNOT(a, c),
p(c),
common_gates.CNOT(b, c),
p(c) ** -1,
common_gates.CNOT(a, c),
p(b),
p(c),
common_gates.CNOT(a, b),
p(a),
p(b) ** -1,
common_gates.CNOT(a, b),
]
return global_phase_operation + [
p(a),
p(b),
Expand Down
14 changes: 14 additions & 0 deletions cirq-core/cirq/ops/three_qubit_gates_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,20 @@ def test_decomposition_respects_locality(gate):
dev.validate_circuit(circuit)


def test_decomposition_all_to_all_connectivity():
decompose_result = cirq.CCZ._decompose_(cirq.LineQubit.range(3), all_to_all_connect=True)
cirq.testing.assert_has_diagram(
cirq.Circuit(decompose_result),
"""
0: ──────────────@──────────────────@───@───T──────@───
│ │ │ │
1: ───@──────────┼───────@───T──────┼───X───T^-1───X───
│ │ │ │
2: ───X───T^-1───X───T───X───T^-1───X───T──────────────
""",
)


def test_diagram():
a, b, c, d = cirq.LineQubit.range(4)
circuit = cirq.Circuit(
Expand Down