Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- #468, #511: The `pyzx` module has been moved to a separate plugin: https://github.com/thierry-martinez/graphix-pyzx/
Consequently, the `pyproject.toml` no longer defines an `extra` dependency group for the `pyzx` package.

- #512: Method `Circuit.simulate_statevector` accepts a `backend: DenseStateBackend[_DenseStateT] | Literal["statevector", "densitymatrix"]` parameter.
- #512: Method `Circuit.simulate` (formerly `Circuit.simulate_statevector`, see #567) accepts a `backend: DenseStateBackend[_DenseStateT] | Literal["statevector", "densitymatrix"]` parameter.

- #567:
- Method `Circuit.simulate_statevector` has been renamed `Circuit.simulate`.
- Method `Pattern.simulate_pattern` has been renamed `Pattern.simulate`.

## [0.3.5] - 2026-03-26

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pattern.draw_graph()
### simulating the pattern

```python
state_out = pattern.simulate_pattern(backend="statevector")
state_out = pattern.simulate(backend="statevector")
```

### and more..
Expand Down
6 changes: 3 additions & 3 deletions benchmarks/statevec.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Here we benchmark our statevector simulator for MBQC.

The methods and modules we use are the followings:
1. :meth:`graphix.pattern.Pattern.simulate_pattern`
1. :meth:`graphix.pattern.Pattern.simulate`
Pattern simulator with statevector backend.
2. :mod:`paddle_quantum.mbqc`
Pattern simulation using :mod:`paddle_quantum.mbqc`.
Expand Down Expand Up @@ -87,12 +87,12 @@ def simple_random_circuit(nqubit, depth):
pattern.minimize_space()
nqubit = len(pattern.extract_nodes())
start = perf_counter()
pattern.simulate_pattern(max_qubit_num=30)
pattern.simulate(max_qubit_num=30)
end = perf_counter()
print(f"width: {width}, nqubit: {nqubit}, depth: {DEPTH}, time: {end - start}")
pattern_time.append(end - start)
start = perf_counter()
circuit.simulate_statevector()
circuit.simulate()
end = perf_counter()
circuit_time.append(end - start)

Expand Down
2 changes: 2 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
autosectionlabel_prefix_document = True

intersphinx_mapping = {
"python": ("https://docs.python.org/3", None),
"networkx": ("https://networkx.github.io/documentation/stable/", None),
"sympy": ("https://docs.sympy.org/latest/", None),
}

sys.path.insert(0, os.path.abspath("../../"))
Expand Down
33 changes: 1 addition & 32 deletions docs/source/generator.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,7 @@ Pattern Generation
.. currentmodule:: graphix.transpiler

.. autoclass:: Circuit

.. automethod:: __init__

.. automethod:: transpile

.. automethod:: simulate_statevector

.. automethod:: cz

.. automethod:: cnot

.. automethod:: h

.. automethod:: s

.. automethod:: x

.. automethod:: y

.. automethod:: z

.. automethod:: rx

.. automethod:: ry

.. automethod:: rz

.. automethod:: j

.. automethod:: ccx

.. automethod:: m
:members:

.. autoclass:: TranspiledPattern

Expand Down
2 changes: 1 addition & 1 deletion docs/source/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ Note that the input state has *teleported* to qubits 6 and 7 after the computati
import networkx as nx
og = OpenGraph(nx.Graph([0, 1]), output_nodes=[0, 1])

>>> print(og.to_pattern().simulate_pattern())
>>> print(og.to_pattern().simulate())
Statevec object with statevector [[ 0.5+0.j 0.5+0.j]
[ 0.5+0.j -0.5+0.j]] and length (2, 2).

Expand Down
80 changes: 1 addition & 79 deletions docs/source/modifier.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,84 +7,6 @@ Pattern Manipulation
.. currentmodule:: graphix.pattern

.. autoclass:: Pattern

.. automethod:: __init__

.. automethod:: add

.. automethod:: extend

.. automethod:: clear

.. automethod:: replace

.. automethod:: reorder_output_nodes

.. automethod:: reorder_input_nodes

.. automethod:: simulate_pattern

.. automethod:: compute_max_degree

.. automethod:: compose

.. automethod:: connected_nodes

.. automethod:: remove_input_nodes

.. automethod:: perform_pauli_pushing

.. automethod:: remove_pauli_measurements

.. automethod:: remove_local_clifford_commands

.. automethod:: to_ascii

.. automethod:: to_unicode

.. automethod:: to_latex

.. automethod:: standardize

.. automethod:: shift_signals

.. automethod:: is_standard

.. automethod:: extract_graph

.. automethod:: extract_nodes

.. automethod:: extract_causal_flow

.. automethod:: extract_gflow

.. automethod:: extract_opengraph

.. automethod:: extract_measurement_commands

.. automethod:: parallelize_pattern

.. automethod:: minimize_space

.. automethod:: draw

.. automethod:: max_space

.. automethod:: to_qasm3

.. automethod:: is_parameterized

.. automethod:: subs

.. automethod:: xreplace

.. automethod:: check_runnability

.. automethod:: map

.. automethod:: infer_pauli_measurements

.. automethod:: to_bloch

:members:

.. autofunction:: shift_outcomes
6 changes: 3 additions & 3 deletions docs/source/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ This is the simplest of the `graph state
<https://en.wikipedia.org/wiki/Graph_state>`_ with nodes = [0, 1] and edge = (0, 1). Any MBQC pattern has a corresponding resource graph state on which the computation occurs only with single-qubit measurements.

We can use the :class:`~graphix.simulator.PatternSimulator` to classically simulate the pattern above and obtain the output state, for default input state of :math:`|+\rangle`.
Alternatively, we can simply call :meth:`~graphix.pattern.Pattern.simulate_pattern` of :class:`~graphix.pattern.Pattern` object to do it in one line:
Alternatively, we can simply call :meth:`~graphix.pattern.Pattern.simulate` of :class:`~graphix.pattern.Pattern` object to do it in one line:

>>> print(pattern.simulate_pattern(backend='statevector'))
>>> print(pattern.simulate(backend='statevector'))
Statevec object with statevector [1.+0.j 0.+0.j] and length (2,).

Note again that we started with :math:`|+\rangle` state so the answer is correct.
Expand Down Expand Up @@ -240,7 +240,7 @@ We can simulate the MBQC pattern with various noise models to understand their e

.. code-block:: python

out_state = pattern.simulate_pattern(backend="statevector")
out_state = pattern.simulate(backend="statevector")

The statevector backend simulates the pattern ideally, without any noise.

Expand Down
4 changes: 2 additions & 2 deletions examples/deutsch_jozsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@
# So the preprocessing has done all the necessary computations, and all nodes are isolated with no further measurements required.
# Let us make sure the result is correct:

out_state = pattern.simulate_pattern()
state = circuit.simulate_statevector().statevec
out_state = pattern.simulate()
state = circuit.simulate().statevec
print("overlap of states: ", np.abs(np.dot(state.psi.flatten().conjugate(), out_state.psi.flatten())))

# %%
2 changes: 1 addition & 1 deletion examples/ghz_with_tn.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
# %%
# Calculate the amplitudes of ``|00...0>`` and ``|11...1>`` states.

tn = pattern.simulate_pattern(backend="tensornetwork")
tn = pattern.simulate(backend="tensornetwork")
print(f"The amplitude of |00...0>: {tn.basis_amplitude(0)}")
print(f"The amplitude of |11...1>: {tn.basis_amplitude(2**n - 1)}")

Expand Down
4 changes: 2 additions & 2 deletions examples/qaoa.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
# %%
# finally, simulate the QAOA circuit

out_state = pattern.simulate_pattern()
state = circuit.simulate_statevector().statevec
out_state = pattern.simulate()
state = circuit.simulate().statevec
print("overlap of states: ", np.abs(np.dot(state.psi.flatten().conjugate(), out_state.psi.flatten())))
# sphinx_gallery_thumbnail_number = 2

Expand Down
2 changes: 1 addition & 1 deletion examples/qft_with_tn.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def qft(circuit: Circuit, n: int) -> None:
import time

t1 = time.time()
tn = pattern.simulate_pattern(backend="tensornetwork")
tn = pattern.simulate(backend="tensornetwork")
value = tn.basis_amplitude(0)
t2 = time.time()
print("amplitude of |00...0> is ", value)
Expand Down
2 changes: 1 addition & 1 deletion examples/rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
# Internally, we are executing the command sequence we inspected above on a statevector simulator.
# We also have a tensornetwork simulation backend to handle larger MBQC patterns. see other examples for how to use it.

out_state = pattern.simulate_pattern(backend="statevector")
out_state = pattern.simulate(backend="statevector")
print(out_state.flatten())

# %%
Expand Down
6 changes: 3 additions & 3 deletions examples/tn_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def ansatz(
# The graph_prep argument is optional,
# but with 'parallel' the TensorNetworkBackend will prepeare the graph state faster.

mbqc_tn = pattern.simulate_pattern(backend="tensornetwork", graph_prep="parallel")
mbqc_tn = pattern.simulate(backend="tensornetwork", graph_prep="parallel")
sv = mbqc_tn.to_statevector().flatten()
print("Statevector after the simulation:", sv)

Expand Down Expand Up @@ -206,7 +206,7 @@ def cost(
pattern.remove_input_nodes()
pattern = pattern.infer_pauli_measurements()
pattern.remove_pauli_measurements(standardize=True)
mbqc_tn = pattern.simulate_pattern(backend="tensornetwork", graph_prep="parallel")
mbqc_tn = pattern.simulate(backend="tensornetwork", graph_prep="parallel")
exp_val: float = 0
for op in ham:
exp_val += np.real(mbqc_tn.expectation_value(op, range(n), optimize=opt))
Expand Down Expand Up @@ -248,7 +248,7 @@ def __call__(
pattern = circuit.transpile().pattern
pattern.standardize()
pattern.shift_signals()
mbqc_tn = pattern.simulate_pattern(backend="tensornetwork", graph_prep="parallel")
mbqc_tn = pattern.simulate(backend="tensornetwork", graph_prep="parallel")

# %%
# Let's use the defined optimizer and find the most probable basis states.
Expand Down
16 changes: 8 additions & 8 deletions graphix/pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ def input_nodes(self) -> list[int]:

@property
def output_nodes(self) -> list[int]:
"""List all nodes that are either `input_nodes` or prepared with `N` commands and that have not been measured with an `M` command."""
"""List all nodes that are either ``input_nodes`` or prepared with ``N`` commands and that have not been measured with an ``M`` command."""
return list(self.__output_nodes) # copy for preventing modification

def __len__(self) -> int:
Expand Down Expand Up @@ -1118,7 +1118,7 @@ def extract_pauli_flow(self) -> PauliFlow[Measurement]:
return self.extract_xzcorrections().to_pauli_flow()

def extract_xzcorrections(self) -> XZCorrections[Measurement]:
"""Extract the XZ-corrections from the current measurement pattern.
r"""Extract the XZ-corrections from the current measurement pattern.

Returns
-------
Expand All @@ -1130,7 +1130,7 @@ def extract_xzcorrections(self) -> XZCorrections[Measurement]:
XZCorrectionsError
If the extracted correction dictionaries are not well formed.
ValueError
If `N` commands in the pattern do not represent a |+⟩ state or if the pattern corrections form closed loops.
If ``N`` commands in the pattern do not represent a :math:`\ket{+}` state or if the pattern corrections form closed loops.

Notes
-----
Expand Down Expand Up @@ -1398,7 +1398,7 @@ def space_list(self) -> list[int]:
return n_list

@overload
def simulate_pattern(
def simulate(
self,
backend: StatevectorBackend | Literal["statevector"] = "statevector",
input_state: State
Expand All @@ -1412,7 +1412,7 @@ def simulate_pattern(
) -> Statevec: ...

@overload
def simulate_pattern(
def simulate(
self,
backend: DensityMatrixBackend | Literal["densitymatrix"],
input_state: State
Expand All @@ -1426,7 +1426,7 @@ def simulate_pattern(
) -> DensityMatrix: ...

@overload
def simulate_pattern(
def simulate(
self,
backend: TensorNetworkBackend | Literal["tensornetwork", "mps"],
input_state: State
Expand All @@ -1439,15 +1439,15 @@ def simulate_pattern(
) -> MBQCTensorNet: ...

@overload
def simulate_pattern(
def simulate(
self,
backend: Backend[_StateT_co],
input_state: Data | None = ...,
rng: Generator | None = ...,
**kwargs: Any,
) -> _StateT_co: ...

def simulate_pattern(
def simulate(
self,
backend: Backend[_StateT_co] | _BackendLiteral = "statevector",
input_state: Data | None = BasicStates.PLUS,
Expand Down
2 changes: 1 addition & 1 deletion graphix/sim/statevec.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ def draw(
>>> circuit = Circuit(2)
>>> circuit.h(0)
>>> circuit.cz(0, 1)
>>> print(circuit.simulate_statevector().statevec.draw())
>>> print(circuit.simulate().statevec.draw())
√2/2(|00⟩ + |01⟩)
"""
return statevec_to_str(
Expand Down
Loading
Loading