Skip to content
Closed

Bots #10

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
43 changes: 43 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: tests
on:
push:
branches: [master]
pull_request:

jobs:
python-tests-pr:
name: python
if: github.event.pull_request.merged != true
runs-on: ubuntu-latest

steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.4.1
with:
access_token: ${{ github.token }}

- name: Checkout phaseshift
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: Install dependencies
shell: bash
run: |
pip install -r requirements.txt
pip install pytest-cov wheel codecov

- name: Install phaseshift
run: |
pip install -e .

- name: Run tests
run: python3 -m pytest src/phaseshift --cov=src/phaseshift --cov-report term-missing --cov-report=html:coverage_html_report --cov-report=xml:coverage.xml

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
44 changes: 44 additions & 0 deletions src/phaseshift/bell_interferometer.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
It was introduced in [this PR by Jake Bulmer and Yuan Yao](https://github.com/XanaduAI/strawberryfields/pull/584#issue-894649549).
"""

from io import StringIO
from collections import defaultdict
from dataclasses import dataclass, field

Expand Down Expand Up @@ -444,3 +445,46 @@ def circuit_reconstruction(decomp: BellDecomp) -> NDArray[np.complex128]:
U = phase_shifter(dim, mode, phi) @ U

return U


def circuit_printer(decomp, width=30, rounding=3):
"""Print the circuit corresponding to the decomposition using qpic syntax.

Given a `BellDecomp` instance, this function prints the circuits in qpic format.
The `BellDecomp` instance can be obtained from the `bell_decomposition` function.

Args:
decomp (BellDecomp): The Bell decomposition containing the parameters of the circuit.

Returns:
### NEED TO WRITE IT

Raises:
TypeError: If the input is not a BellDecomp instance.
"""
output = StringIO()
dim = decomp.dim
# Apply the phase shifters at the input
for mode, phi in decomp.phi_input.items():
print(f"{mode} G ${round(phi/np.pi, rounding)}$ width={width}", file=output)

# Iterate through the layers of the circuit
for layer in range(dim):
# Apply the sMZIs in the layer
for mode in range(layer % 2, dim - 1, 2):
delta = round((decomp.delta[mode, layer] / np.pi) % 1, rounding)
sigma = round((decomp.sigma[mode, layer] / np.pi) % 1, rounding)
print(
f"{mode} {mode+1} G $\\genfrac{{}}{{}}{{0pt}}{{}}{{{delta}}}{{{sigma}}}$ width={width}",
file=output,
)
if (dim - 1, layer) in decomp.phi_edge:
phi_bottom = round((decomp.phi_edge[dim - 1, layer] / np.pi) % 1, rounding)
print(f"{dim-1} G ${phi_bottom}$ width={width}", file=output)
# Apply the phase shifters at the output
for mode, phi in decomp.phi_output.items():
phi = round((phi / np.pi) % 1, rounding)
print(f"{mode} G ${phi}$ width={width}", file=output)
captured_text = output.getvalue()
output.close()
return captured_text
Loading