Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
multiphaseCFD committed Feb 12, 2025
1 parent a7514b7 commit 8ce73cd
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 0 deletions.
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

0 comments on commit 8ce73cd

Please sign in to comment.