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

[FTQC] Add Lattice class to ftqc module #6958

Merged
merged 49 commits into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
8ce73cd
initial commit
multiphaseCFD Feb 12, 2025
3d7387c
use grid_graph API to generate 1,2,3D lattice structure
multiphaseCFD Feb 13, 2025
6ba944a
remove print
multiphaseCFD Feb 13, 2025
00de819
drop labelling and draw support
multiphaseCFD Feb 14, 2025
a2d4050
add lattice generation support
multiphaseCFD Feb 18, 2025
ce8706b
add unit tests
multiphaseCFD Feb 18, 2025
d07ddcd
remove graphiz dependency
multiphaseCFD Feb 18, 2025
431f158
tidy up
multiphaseCFD Feb 18, 2025
799faba
make format
multiphaseCFD Feb 18, 2025
24aeb5c
Merge branch 'master' into ftqc_cluster_state_test
multiphaseCFD Feb 18, 2025
25e74f6
update docstr
multiphaseCFD Feb 18, 2025
11475b8
add attribute setter
multiphaseCFD Feb 18, 2025
cded466
add changelog
multiphaseCFD Feb 18, 2025
506947b
update format
multiphaseCFD Feb 18, 2025
25ac1cc
add docstr to unit tests
multiphaseCFD Feb 18, 2025
0f3bfa2
disables the inconsistent-return-statements check
multiphaseCFD Feb 18, 2025
218fd1f
make format
multiphaseCFD Feb 18, 2025
e18978f
fix codefactor warning
multiphaseCFD Feb 18, 2025
5ff1920
tidy up code
multiphaseCFD Feb 18, 2025
c2300a0
make format
multiphaseCFD Feb 18, 2025
c4d6881
update docstr
multiphaseCFD Feb 18, 2025
58748fc
Merge branch 'master' into ftqc_cluster_state_test
multiphaseCFD Feb 18, 2025
fa89133
fix code factor issues
multiphaseCFD Feb 18, 2025
6bfef48
update py unit test file name
multiphaseCFD Feb 18, 2025
8306156
fix pylint issues
multiphaseCFD Feb 18, 2025
98d0c9c
Update doc/releases/changelog-dev.md
multiphaseCFD Feb 19, 2025
668da34
apply some suggestions
multiphaseCFD Feb 20, 2025
c86e142
remove pylint
multiphaseCFD Feb 24, 2025
0df3271
apply some suggestions
multiphaseCFD Feb 24, 2025
6430837
Merge branch 'master' into ftqc_cluster_state_test
multiphaseCFD Feb 24, 2025
f3ad91b
update typo
multiphaseCFD Feb 24, 2025
11adf72
update codes
multiphaseCFD Feb 24, 2025
45576f9
update LatticeShape class and map
multiphaseCFD Feb 26, 2025
59000f5
make format
multiphaseCFD Feb 26, 2025
bcb6fc7
apply some changes
multiphaseCFD Feb 28, 2025
b276afc
apply more suggestions
multiphaseCFD Feb 28, 2025
6199833
Merge branch 'master' into ftqc_cluster_state_test
multiphaseCFD Feb 28, 2025
3c94961
fix codecov warning
multiphaseCFD Feb 28, 2025
cb1988a
udpate changelog
multiphaseCFD Feb 28, 2025
f690dbe
Merge branch 'master' into ftqc_cluster_state_test
multiphaseCFD Feb 28, 2025
0d88a3f
Merge branch 'master' into ftqc_cluster_state_test
multiphaseCFD Feb 28, 2025
d4e2f0e
update property method
multiphaseCFD Feb 28, 2025
e2cea57
Merge branch 'master' into ftqc_cluster_state_test
multiphaseCFD Feb 28, 2025
d450a0d
Merge branch 'master' into ftqc_cluster_state_test
multiphaseCFD Feb 28, 2025
87981e0
fix codecov complains
multiphaseCFD Feb 28, 2025
74e14fb
fix typo
multiphaseCFD Feb 28, 2025
bf558b0
Merge branch 'master' into ftqc_cluster_state_test
multiphaseCFD Feb 28, 2025
349245e
Update tests/ftqc/test_ftqc_lattice.py
multiphaseCFD Feb 28, 2025
49c6a97
Update tests/ftqc/test_ftqc_lattice.py
multiphaseCFD Feb 28, 2025
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
123 changes: 123 additions & 0 deletions pennylane/ftqc/cluster_state.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# Copyright 2025 Xanadu Quantum Technologies Inc.
# 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

# http://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.

"""This module contains the classes and functions for creating and diagonalizing
midcircuit measurements with a parameterized measurement axis."""


import networkx as nx
import math

Check notice on line 19 in pennylane/ftqc/cluster_state.py

View check run for this annotation

codefactor.io / CodeFactor

pennylane/ftqc/cluster_state.py#L19

standard import "math" should be placed before third party import "networkx" (wrong-import-order)
import matplotlib.pyplot as plt

Check notice on line 20 in pennylane/ftqc/cluster_state.py

View check run for this annotation

codefactor.io / CodeFactor

pennylane/ftqc/cluster_state.py#L20

Unused matplotlib.pyplot imported as plt (unused-import)
from networkx import Graph


class ClusterState:

Check notice on line 24 in pennylane/ftqc/cluster_state.py

View check run for this annotation

codefactor.io / CodeFactor

pennylane/ftqc/cluster_state.py#L24

Too few public methods (0/2) (too-few-public-methods)
"""Class of stabilizer-formalism cluster state for measurement-based quantum computing(MBQC).

Cluster states is a specific instance of a graph state as illustated in [Entanglement in Graph States and its Applications, arXiv:quant-ph/0602096].
With cluster states, univeral computation can be realized without the need of making use of any controlled two-system quantum gates.

Vertex connectivity:
A cluster state can be defined in 1,2 and 3 dimensions, correponding to 1-D chain lattice, 2-D rectangular lattice and 3-D cubic lattices.

Stabilizer:
Each vertex is a cluster state represents a qubit and there is one stabilizer generator S_j per graph vertex j of the form
S_j = X_{j} \prod_{k\in N(j)} Z_k

Check notice on line 35 in pennylane/ftqc/cluster_state.py

View check run for this annotation

codefactor.io / CodeFactor

pennylane/ftqc/cluster_state.py#L35

Anomalous backslash in string: '\i'. String constant might be missing an r prefix. (anomalous-backslash-in-string)

Check notice on line 35 in pennylane/ftqc/cluster_state.py

View check run for this annotation

codefactor.io / CodeFactor

pennylane/ftqc/cluster_state.py#L35

Anomalous backslash in string: '\p'. String constant might be missing an r prefix. (anomalous-backslash-in-string)
where the neighborhood N(j) is the set of vertices which share an edge with j [Cluster-state code, https://errorcorrectionzoo.org/c/cluster_state].

#TODO: do we need



Args:

graph: nx.Graph

"""
_short_name = "cluster_state"

def __init__(self, dims: list = None, graph: Graph = None):

Check notice on line 49 in pennylane/ftqc/cluster_state.py

View check run for this annotation

codefactor.io / CodeFactor

pennylane/ftqc/cluster_state.py#L49

Unused argument 'graph' (unused-argument)
assert len(dims) <= 3, f"{len(dims)}-dimensional cluster state is not supported."
self._graph = len(dims)

Check notice on line 52 in pennylane/ftqc/cluster_state.py

View check run for this annotation

codefactor.io / CodeFactor

pennylane/ftqc/cluster_state.py#L52

Trailing whitespace (trailing-whitespace)

Check notice on line 53 in pennylane/ftqc/cluster_state.py

View check run for this annotation

codefactor.io / CodeFactor

pennylane/ftqc/cluster_state.py#L53

Trailing whitespace (trailing-whitespace)
def _create_1d_chain(dims):

Check notice on line 54 in pennylane/ftqc/cluster_state.py

View check run for this annotation

codefactor.io / CodeFactor

pennylane/ftqc/cluster_state.py#L54

Method '_create_1d_chain' should have "self" as first argument (no-self-argument)
labels = list(range(dims[0]))
G = nx.Graph()
for label in labels:
G.add_node(label)

Check notice on line 59 in pennylane/ftqc/cluster_state.py

View check run for this annotation

codefactor.io / CodeFactor

pennylane/ftqc/cluster_state.py#L59

Trailing whitespace (trailing-whitespace)
for label in labels[1:]:
G.add_edge(label - 1, label, label='CNOT')

Check notice on line 62 in pennylane/ftqc/cluster_state.py

View check run for this annotation

codefactor.io / CodeFactor

pennylane/ftqc/cluster_state.py#L62

Trailing whitespace (trailing-whitespace)
return G

def _create_2d_rectangle(dims):

Check notice on line 65 in pennylane/ftqc/cluster_state.py

View check run for this annotation

codefactor.io / CodeFactor

pennylane/ftqc/cluster_state.py#L65

Method '_create_2d_rectangle' should have "self" as first argument (no-self-argument)
assert len(dims) == 2, f"Rectangle lattice requires a 2 dims input, but {len(dims)} dim is provided"
num_labels = math.prod(dims)
labels = list(range(num_labels))
G = nx.Graph()
# Add nodes to the graph
for label in labels:
G.add_node(label)

Check notice on line 73 in pennylane/ftqc/cluster_state.py

View check run for this annotation

codefactor.io / CodeFactor

pennylane/ftqc/cluster_state.py#L73

Trailing whitespace (trailing-whitespace)
# Add row edges to the graph
for j in range(dims[1]):
for i in range(dims[0] - 1):
start = j*dims[0] + i
end = start + 1
G.add_edge(start, end, lable='CNOT')

Check notice on line 80 in pennylane/ftqc/cluster_state.py

View check run for this annotation

codefactor.io / CodeFactor

pennylane/ftqc/cluster_state.py#L80

Trailing whitespace (trailing-whitespace)
for j in range(dims[1] - 1):
for i in range(dims[0]):
start = j*dims[0] + i
end = start + dims[0]
G.add_edge(start, end, label='CNOT')

Check notice on line 86 in pennylane/ftqc/cluster_state.py

View check run for this annotation

codefactor.io / CodeFactor

pennylane/ftqc/cluster_state.py#L86

Trailing whitespace (trailing-whitespace)
return G

Check notice on line 88 in pennylane/ftqc/cluster_state.py

View check run for this annotation

codefactor.io / CodeFactor

pennylane/ftqc/cluster_state.py#L88

Trailing whitespace (trailing-whitespace)
def _create_3d_cubic(dims):

Check notice on line 89 in pennylane/ftqc/cluster_state.py

View check run for this annotation

codefactor.io / CodeFactor

pennylane/ftqc/cluster_state.py#L89

Method '_create_3d_cubic' should have "self" as first argument (no-self-argument)
assert len(dims) == 3, f"cubic lattice requires a 3 dims input, but {len(dims)} dim is provided"
num_labels = math.prod(dims)
labels = list(range(num_labels))
G = nx.Graph()
# Add nodes to the graph
for label in labels:
G.add_node(label)

Check notice on line 97 in pennylane/ftqc/cluster_state.py

View check run for this annotation

codefactor.io / CodeFactor

pennylane/ftqc/cluster_state.py#L97

Trailing whitespace (trailing-whitespace)
# Add row edges to the graph
for k in range(dims[2]):
for j in range(dims[1]):
for i in range(dims[0] - 1):
start = k*dims[1]*dims[0]+ j*dims[0] + i
end = start + 1
G.add_edge(start, end, label='CNOT')

Check notice on line 105 in pennylane/ftqc/cluster_state.py

View check run for this annotation

codefactor.io / CodeFactor

pennylane/ftqc/cluster_state.py#L105

Trailing whitespace (trailing-whitespace)
for k in range(dims[2]):
for j in range(dims[1] - 1):
for i in range(dims[0]):
start = k*dims[1]*dims[0]+ j*dims[0] + i
end = start + dims[0]
G.add_edge(start, end, label='CNOT')

Check notice on line 112 in pennylane/ftqc/cluster_state.py

View check run for this annotation

codefactor.io / CodeFactor

pennylane/ftqc/cluster_state.py#L112

Trailing whitespace (trailing-whitespace)
for k in range(dims[2]-1):
for j in range(dims[1]):
for i in range(dims[0]):
start = k*dims[1]*dims[0]+ j*dims[0] + i
end = start + dims[1]*dims[0]
G.add_edge(start, end, label='CNOT')

Check notice on line 119 in pennylane/ftqc/cluster_state.py

View check run for this annotation

codefactor.io / CodeFactor

pennylane/ftqc/cluster_state.py#L119

Trailing whitespace (trailing-whitespace)
return G



Check notice on line 123 in pennylane/ftqc/cluster_state.py

View check run for this annotation

codefactor.io / CodeFactor

pennylane/ftqc/cluster_state.py#L123

Trailing newlines (trailing-newlines)
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ isort==5.13.2
pylint==2.7.4
rich>=13.7.1
tach==0.13.1
graphviz