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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
fail-fast: false
matrix:
os: ['ubuntu-latest', 'windows-2022', 'macos-latest']
python: ['3.8', '3.9', '3.10', '3.11']
python: ['3.9', '3.10', '3.11', '3.12']

name: "Python ${{ matrix.python }} / ${{ matrix.os }}"
runs-on: ${{ matrix.os }}
Expand Down
2 changes: 1 addition & 1 deletion docs/source/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Then we define a circuit:
# generate a slightly modified GHZ state generation pattern
circuit = Circuit(3)
simple_circ(circuit)
pattern = circuit.transpile()
pattern = circuit.transpile().pattern

# plot the pattern
nodes, edges = pattern.get_graph()
Expand Down
8 changes: 6 additions & 2 deletions graphix_perceval/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
import graphix
import perceval as pcvl
import sympy as sp
from graphix.extraction import ResourceGraph, ResourceType, get_fusion_network_from_graph
from graphix.extraction import (
ResourceGraph,
ResourceType,
get_fusion_network_from_graph,
)
from perceval import components as comp

from graphix_perceval.clifford import CLIFFORD_TO_PERCEVAL_POLAR
Expand Down Expand Up @@ -34,7 +38,7 @@ def pattern2graphstate(
graph_state = graphix.GraphState(nodes=nodes, edges=edges, vops=vop_init)
phasedict = {}
for command in pattern.get_measurement_commands():
phasedict[command[1]] = command[3]
phasedict[command.node] = command.angle

output_nodes = pattern.output_nodes
return graph_state, phasedict, output_nodes
Expand Down
23 changes: 14 additions & 9 deletions graphix_perceval/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import itertools
import sys
import warnings
from _collections_abc import dict_items
from enum import Enum

import perceval as pcvl
import sympy as sp
from _collections_abc import dict_items
from perceval.algorithm import Sampler
from perceval.utils import PostSelect
from tabulate import tabulate
Expand Down Expand Up @@ -198,11 +198,9 @@ def get_probability_distribution(
self.set_postselection()

sampler = Sampler(self.processor)
probs = PhotonDistribution(sampler.probs()["results"])

if format_result:
probs.replace_keys(self.output_states)

sampler.add_iteration()
sampler.sample_count(10000)
probs = sampler.probs()
return probs

def sample(self, num_samples=1024, format_result: bool = True, postselection: bool = True) -> PhotonCount:
Expand Down Expand Up @@ -241,11 +239,18 @@ def set_postselection(self):
"""Postselect the results according to the pattern."""
ps = PostSelect()
for ph in self.get_readout_photons():
ps.eq([2 * ph.id, 2 * ph.id + 1], 1)
ps_ = PostSelect(f"[{2*ph.id}, {2*ph.id + 1}] == 1")
ps.merge(ps_)
for ph in self.get_compute_photons():
ps.eq([2 * ph.id], 0).eq([2 * ph.id + 1], 1)
ps_ = PostSelect(f"[{2*ph.id}] == 0")
ps.merge(ps_)
ps_ = PostSelect(f"[{2*ph.id + 1}] == 1")
ps.merge(ps_)
for ph in self.get_witness_photons():
ps.eq([2 * ph.id], 0).eq([2 * ph.id + 1], 1)
ps_ = PostSelect(f"[{2*ph.id}] == 0")
ps.merge(ps_)
ps_ = PostSelect(f"[{2*ph.id + 1}] == 1")
ps.merge(ps_)

self.processor.set_postselection(ps)

Expand Down
2 changes: 1 addition & 1 deletion graphix_perceval/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.0.2"
__version__ = "0.0.3"
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
graphix>=0.2.8
perceval-quandela>=0.9.1
graphix>=0.3.0
perceval-quandela>=0.12.0
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
"Development Status :: 4 - Beta",
"Environment :: Console",
"Intended Audience :: Science/Research",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
"Topic :: Scientific/Engineering :: Physics",
],
"python_requires": ">=3.8,<3.12",
"python_requires": ">=3.9,<3.13",
"install_requires": requirements,
"extras_require": {},
}
Expand Down
9 changes: 6 additions & 3 deletions tests/test_clifford.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import unittest

from graphix.clifford import CLIFFORD
from graphix_perceval.clifford import CLIFFORD_TO_PERCEVAL_BS, CLIFFORD_TO_PERCEVAL_POLAR
from sympy import matrix2numpy
import numpy as np
import perceval as pcvl
from graphix.clifford import CLIFFORD
from graphix_perceval.clifford import (
CLIFFORD_TO_PERCEVAL_BS,
CLIFFORD_TO_PERCEVAL_POLAR,
)
from sympy import matrix2numpy


class TestConverter(unittest.TestCase):
Expand Down
19 changes: 9 additions & 10 deletions tests/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import numpy as np
from graphix import Circuit

from graphix_perceval.converter import to_perceval
from graphix_perceval.experiment import PhotonDistribution

Expand All @@ -12,7 +11,7 @@ def test_sampling_circuit_wo_postselection(self):
circuit = Circuit(2)
circuit.h(1)
circuit.cnot(0, 1)
pattern = circuit.transpile()
pattern = circuit.transpile().pattern
pattern.standardize()
pattern.shift_signals()

Expand All @@ -28,7 +27,7 @@ def test_sampling_circuit_w_postselection(self):
circuit = Circuit(2)
circuit.h(1)
circuit.cnot(0, 1)
pattern = circuit.transpile()
pattern = circuit.transpile().pattern
pattern.standardize()
pattern.shift_signals()

Expand All @@ -44,7 +43,7 @@ def test_sampling_circuit_w_postselection(self):
def test_zero_state_creation_wo_pauli_meas(self):
circuit = Circuit(1) # initialize with |+>
circuit.h(0)
pattern = circuit.transpile()
pattern = circuit.transpile().pattern
pattern.standardize()
pattern.shift_signals()

Expand All @@ -60,7 +59,7 @@ def test_one_state_creation_wo_pauli_meas(self):
circuit = Circuit(1) # initialize with |+>
circuit.h(0)
circuit.x(0)
pattern = circuit.transpile()
pattern = circuit.transpile().pattern
pattern.standardize()
pattern.shift_signals()

Expand All @@ -76,7 +75,7 @@ def test_rotated_one_qubit_state_creation_wo_pauli_meas(self):
circuit = Circuit(1) # initialize with |+>
circuit.h(0)
circuit.rx(0, np.pi / 1.23)
pattern = circuit.transpile()
pattern = circuit.transpile().pattern
pattern.standardize()
pattern.shift_signals()

Expand All @@ -93,7 +92,7 @@ def test_bell_state_phi_plus_creation_wo_pauli_meas(self):
circuit = Circuit(2) # initialize with |+> \otimes |+>
circuit.h(1)
circuit.cnot(0, 1)
pattern = circuit.transpile()
pattern = circuit.transpile().pattern
pattern.standardize()
pattern.shift_signals()

Expand All @@ -110,7 +109,7 @@ def test_bell_state_phi_plus_creation_with_pauli_meas(self):
circuit = Circuit(2) # initialize with |+> \otimes |+>
circuit.h(1)
circuit.cnot(0, 1)
pattern = circuit.transpile()
pattern = circuit.transpile().pattern
pattern.standardize()
pattern.shift_signals()
pattern.perform_pauli_measurements()
Expand All @@ -130,7 +129,7 @@ def test_ghz_state_creation_with_pauli_meas(self):
circuit.h(2)
circuit.cnot(0, 1)
circuit.cnot(1, 2)
pattern = circuit.transpile()
pattern = circuit.transpile().pattern
pattern.standardize()
pattern.shift_signals()
pattern.perform_pauli_measurements()
Expand All @@ -149,7 +148,7 @@ def test_bell_state_and_ry_with_pauli_meas(self):
circuit.h(1)
circuit.cnot(0, 1)
circuit.ry(1, np.pi / 4)
pattern = circuit.transpile()
pattern = circuit.transpile().pattern
pattern.standardize()
pattern.shift_signals()
pattern.perform_pauli_measurements()
Expand Down
6 changes: 3 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[tox]
envlist = py38, py39, py310, lint
envlist = py39, py310, py311, py312, lint

[gh-actions]
python =
3.8: lint, py38
3.9: py39
3.9: lint, py39
3.10: py310
3.11: py311
3.12: py312

[testenv]
description = Run the unit tests
Expand Down