Skip to content

Commit

Permalink
Merge pull request #203 from Budapest-Quantum-Computing-Group/kz-bump
Browse files Browse the repository at this point in the history
bump: 1.0 -> 2.0.0
  • Loading branch information
Kolarovszki authored Oct 30, 2022
2 parents aa4eebb + 52f56ef commit 2c091d6
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 5 deletions.
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
# Changelog


## [2.0.0] - 2022-10-30

### Added

- A simulator class called `TensorflowPureFockSimulator`, which uses Tensorflow
and is able to calculate gradients.

### Changed

- By enabling Tensorflow support, we dropped support for customizing the
permanent, hafnian and loop hafnian calculations through `Config`.


## [1.0.1] - 2022-09-05

### Fixed

- `SamplingSimulator` along with `Loss` using uniform transmissivity
(transmittance) parameters and `ParticleNumberMeasurement` produced only-zero
samples instead of the expected samples.


## [1.0.0] - 2022-04-26

### Added
Expand Down
2 changes: 1 addition & 1 deletion piquasso/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,4 @@
"LossyInterferometer",
]

__version__ = "1.0.0"
__version__ = "2.0.0"
5 changes: 4 additions & 1 deletion piquasso/_backends/sampling/calculations.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ def _get_sampling_simulation_strategy(
_, singular_values, _ = np.linalg.svd(state.interferometer)

if np.all(np.isclose(singular_values, singular_values[0])):
return GeneralizedCliffordsUniformLossesSimulationStrategy(permanent_calculator)
uniform_transmission_probability = singular_values[0] ** 2
return GeneralizedCliffordsUniformLossesSimulationStrategy(
permanent_calculator, uniform_transmission_probability
)

return LossyNetworksGeneralizedCliffordsSimulationStrategy(permanent_calculator)
10 changes: 8 additions & 2 deletions piquasso/instructions/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,17 @@ def __init__(self, theta: float, mean_thermal_excitation: float = 0) -> None:


class Loss(Gate, _mixins.ScalingMixin):
"""Applies a loss channel to the state.
r"""Applies a loss channel to the state.
The transmissivity is defined by :math:`t = \cos \theta`, where :math:`\theta` is
the beamsplitter parameter and the angle between the initial and resulting state.
Considering only one particle, :math:`1-t^2` is the probability of losing this
particle.
Note:
Currently, this instruction can only be used along with
- Currently, this instruction can only be used along with
:class:`~piquasso._backends.sampling.simulator.SamplingSimulator`.
- The parameter `transmissivity` is usually called `transmittance`.
"""

def __init__(self, transmissivity: np.ndarray) -> None:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

setup(
name="piquasso",
version="1.0.0",
version="2.0.0",
packages=find_packages(exclude=["tests.*", "tests", "scripts", "scripts.*"]),
maintainer="Budapest Quantum Computing Group",
maintainer_email="[email protected]",
Expand Down
53 changes: 53 additions & 0 deletions tests/backends/sampling/test_channels.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#
# Copyright 2021-2022 Budapest Quantum Computing Group
#
# 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.

import numpy as np

import piquasso as pq


def test_Loss_uniform():
with pq.Program() as program:
pq.Q() | pq.StateVector([1, 1, 1, 0, 0])

pq.Q(all) | pq.Loss(transmissivity=0.9)

simulator = pq.SamplingSimulator(d=5)
state = simulator.execute(program, shots=1).state

assert state.is_lossy

singular_values = np.linalg.svd(state.interferometer)[1]

assert np.allclose(singular_values, [0.9, 0.9, 0.9, 0.9, 0.9])


def test_Loss_non_uniform():
with pq.Program() as program:
pq.Q() | pq.StateVector([1, 1, 1, 0, 0])

pq.Q(0) | pq.Loss(transmissivity=0.4)
pq.Q(1) | pq.Loss(transmissivity=0.5)

simulator = pq.SamplingSimulator(d=5)
state = simulator.execute(program, shots=1).state

assert state.is_lossy

singular_values = np.linalg.svd(state.interferometer)[1]

assert len(singular_values[np.isclose(singular_values, 0.4)]) == 1
assert len(singular_values[np.isclose(singular_values, 0.5)]) == 1
assert len(singular_values[np.isclose(singular_values, 1.0)]) == 3

0 comments on commit 2c091d6

Please sign in to comment.