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

Use PEP8 naming #199

Merged
merged 12 commits into from
Aug 26, 2024
6 changes: 3 additions & 3 deletions benchmarks/statevec.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import numpy as np
from paddle import to_tensor
from paddle_quantum.mbqc.qobject import Circuit as PaddleCircuit
from paddle_quantum.mbqc.simulator import MBQC as PaddleMBQC
from paddle_quantum.mbqc.transpiler import transpile as PaddleTranspile
from paddle_quantum.mbqc.simulator import MBQC as PaddleMBQC # noqa: N811
from paddle_quantum.mbqc.transpiler import transpile as paddle_transpile

from graphix import Circuit

Expand Down Expand Up @@ -127,7 +127,7 @@ def translate_graphix_rc_into_paddle_quantum_circuit(graphix_circuit: Circuit) -
for width in test_cases_for_paddle_quantum:
graphix_circuit = graphix_circuits[width]
paddle_quantum_circuit = translate_graphix_rc_into_paddle_quantum_circuit(graphix_circuit)
pat = PaddleTranspile(paddle_quantum_circuit)
pat = paddle_transpile(paddle_quantum_circuit)
mbqc = PaddleMBQC()
mbqc.set_pattern(pat)
start = perf_counter()
Expand Down
10 changes: 4 additions & 6 deletions docs/source/lc-mbqc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,18 @@ Furthermore, we can toggle through `equivalent graphs`, graph states with differ
:align: center
:alt: equivalent graphs

These graphs were generatetd using :class:`~graphix.graphsim.GraphState`, which has two methods to generate equivalent graphs, :meth:`~graphix.graphsim.GraphState.equivalent_graph_E1` and :meth:`~graphix.graphsim.GraphState.equivalent_graph_E2`, which have different conditions for applying them. For this graph, we can use :meth:`~graphix.graphsim.GraphState.equivalent_graph_E2` to any connected nodes since the graph is loopless.
These graphs were generatetd using :class:`~graphix.graphsim.GraphState`, which has two methods to generate equivalent graphs, :meth:`~graphix.graphsim.GraphState.equivalent_graph_e1` and :meth:`~graphix.graphsim.GraphState.equivalent_graph_e2`, which have different conditions for applying them. For this graph, we can use :meth:`~graphix.graphsim.GraphState.equivalent_graph_e2` to any connected nodes since the graph is loopless.

.. code-block:: python

# series of equivalent graph transformations
g = GraphState(nodes=[0,1,2,3],edges=[(0,1),(1,2),(2,3),(3,1)]) # leftmost graph
state1 = g.to_statevector()
g.equivalent_graph_E2(0, 1) # second graph
g.equivalent_graph_e2(0, 1) # second graph
state2 = g.to_statevector()
g.equivalent_graph_E2(2, 0) # third graph
g.equivalent_graph_e2(2, 0) # third graph
state3 = g.to_statevector()
g.equivalent_graph_E2(0, 3) # rightmost graph
g.equivalent_graph_e2(0, 3) # rightmost graph
state4 = g.to_statevector()

checking that states 1-4 all are the same up to global phase:
Expand Down Expand Up @@ -144,5 +144,3 @@ References and notes
.. [#graph] In fact, it is known that all stabilizer state can be represented by graph states up to local (single-qubit) Clifford operations.

.. [#el] Elliot `et al`., `J. Phys. A 43, 025301 (2010) <https://iopscience.iop.org/article/10.1088/1751-8113/43/2/025301/meta>`_ and `PRA 77, 042307 (2008) <https://journals.aps.org/pra/abstract/10.1103/PhysRevA.77.042307>`_. We note that there are numerous stabilizer simulators available, but this graph simulator formulation by Elliot `et al.` is suitable for optimizing MBQC for three reasons: 1. this is a direct simulator of graph states, 2. the local-Clifford decoration is expressed by up to one H, S and Z gates, which are easier to handle than all 24 possible single-qubit Clifford gates, and 3. this has a method to toggle through all possible equivalent graphs (LC decorated graphs representing exactly the same stabilizer state), to minimize the connectivity of the graph state (to minimize the complexity of MBQC operation and classical simulation).


File renamed without changes.
8 changes: 4 additions & 4 deletions examples/MBQCvqe.py → examples/mbqc_vqe.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
from graphix import Circuit
from graphix.simulator import PatternSimulator

Z = np.array([[1, 0], [0, -1]])
X = np.array([[0, 1], [1, 0]])


# %%
# Define the Hamiltonian for the VQE problem (Example: H = Z0Z1 + X0 + X1)
def create_hamiltonian():
Z = np.array([[1, 0], [0, -1]])
X = np.array([[0, 1], [1, 0]])
H = np.kron(Z, Z) + np.kron(X, np.eye(2)) + np.kron(np.eye(2), X)
return H
return np.kron(Z, Z) + np.kron(X, np.eye(2)) + np.kron(np.eye(2), X)


# %%
Expand Down
6 changes: 4 additions & 2 deletions examples/qnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@

np.random.seed(0)


Z_OP = np.array([[1, 0], [0, -1]])

# %%
# Dataset
# -----------------
Expand Down Expand Up @@ -74,7 +77,6 @@ def __init__(self, n_qubits, n_layers, n_features):
assert n_features % 3 == 0, "n_features must be a multiple of 3"

# Pauli Z operator on all qubits
Z_OP = np.array([[1, 0], [0, -1]])
operator = [Z_OP] * self.n_qubits
self.obs = reduce(np.kron, operator)
self.cost_values = [] # to store cost values during optimization
Expand Down Expand Up @@ -155,7 +157,7 @@ def get_expectation_value(self, sv):
Calculates the expectation value of an PauliZ obeservable given a state vector.

Args:
sv: sSate vector represented as a numpy array.
sv: State vector represented as a numpy array.

Returns:
the expectation value of a quantum observable.
Expand Down
4 changes: 2 additions & 2 deletions examples/rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@
# Let us compare with statevector simulation of the original circuit:

state = Statevec(nqubit=2, data=BasicStates.ZERO) # starts with |0> states
state.evolve_single(Ops.Rx(theta[0]), 0)
state.evolve_single(Ops.Rx(theta[1]), 1)
state.evolve_single(Ops.rx(theta[0]), 0)
state.evolve_single(Ops.rx(theta[1]), 1)
print("overlap of states: ", np.abs(np.dot(state.psi.flatten().conjugate(), out_state.psi.flatten())))

# %%
Expand Down
4 changes: 2 additions & 2 deletions graphix/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@
"""
if px + py + pz > 1:
raise ValueError("The sum of probabilities must not exceed 1.")
pI = 1 - px - py - pz
p_i = 1 - px - py - pz

Check warning on line 127 in graphix/channels.py

View check run for this annotation

Codecov / codecov/patch

graphix/channels.py#L127

Added line #L127 was not covered by tests
return KrausChannel(
[
{"coef": np.sqrt(1 - pI), "operator": np.eye(2)},
{"coef": np.sqrt(1 - p_i), "operator": np.eye(2)},
{"coef": np.sqrt(px / 3.0), "operator": Ops.x},
{"coef": np.sqrt(py / 3.0), "operator": Ops.y},
{"coef": np.sqrt(pz / 3.0), "operator": Ops.z},
Expand Down
Loading
Loading