Skip to content

Commit

Permalink
rename: Operation -> Instruction
Browse files Browse the repository at this point in the history
All the operations got renamed to instructions.
  • Loading branch information
kolarovszki-elte committed Mar 25, 2021
1 parent 64571b6 commit 00f4af7
Show file tree
Hide file tree
Showing 57 changed files with 327 additions and 326 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ in their `__init__()` function: they are expected to accept a named parameter
`qnode_type` but they don't. If you add the parameter by hand it will work
fine.

**The benchmarks, as of now, only work for qubit operations!**
**The benchmarks, as of now, only work for qubit instructions!**

## Generating documentation

Expand Down
8 changes: 4 additions & 4 deletions docs/appendix/gaussian.rst
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Let :math:`\vec{m}` denote an index set, which corresponds to the parameter
`modes`.

Let :math:`P, A \in \mathbb{C}^{k \times k},\, k \in [d]` be a passive and an
active transformation, respectively. An active operation transforms the vector
active transformation, respectively. An active transformation transforms the vector
of annihilation operators in the following manner:

.. math::
Expand Down Expand Up @@ -136,7 +136,7 @@ Then each row of the mode :math:`i` will be updated according to the fact that
Displacement
~~~~~~~~~~~~

Applies the displacement operation to the state.
Applies the displacement instruction to the state.

.. math::
D(\alpha) = \exp(\alpha \hat{a}_i^\dagger - \alpha^* \hat{a}_i),
Expand All @@ -145,7 +145,7 @@ where :math:`\alpha \in \mathbb{C}` is a parameter, :math:`\hat{a}_i` and
:math:`\hat{a}_i^\dagger` are the annihilation and creation operators on the
:math:`i`-th mode, respectively.

The displacement operation acts on the annihilation and creation operators
The displacement instruction acts on the annihilation and creation operators
in the following way:

.. math::
Expand Down Expand Up @@ -180,7 +180,7 @@ Note, that :math:`\alpha` is often written in the form
\alpha = r \exp(i \phi),
where :math:`r \geq 0` and :math:`\phi \in [ 0, 2 \pi )`. When two parameters
are specified for this operation, the first is interpreted as :math:`r`, and the
are specified for this instruction, the first is interpreted as :math:`r`, and the
second one as :math:`\phi`.

Also note, that the displacement cannot be categorized as an active or passive
Expand Down
8 changes: 4 additions & 4 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ A fast and easy-to-use Photonic Quantum Computer Simulator.

.. toctree::
:maxdepth: 3
:caption: Operations:
:caption: Instructions:
:hidden:

operations/preparations
operations/gates
operations/measurements
instructions/preparations
instructions/gates
instructions/measurements

.. toctree::
:maxdepth: 3
Expand Down
5 changes: 5 additions & 0 deletions docs/instructions/gates.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Gates
=====

.. automodule:: piquasso.instructions.gates
:members:
5 changes: 5 additions & 0 deletions docs/instructions/measurements.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Measurements
============

.. automodule:: piquasso.instructions.measurements
:members:
5 changes: 5 additions & 0 deletions docs/instructions/preparations.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Preparations
============

.. automodule:: piquasso.instructions.preparations
:members:
5 changes: 0 additions & 5 deletions docs/operations/gates.rst

This file was deleted.

5 changes: 0 additions & 5 deletions docs/operations/measurements.rst

This file was deleted.

5 changes: 0 additions & 5 deletions docs/operations/preparations.rst

This file was deleted.

6 changes: 3 additions & 3 deletions piquasso/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from piquasso.core.registry import _use_plugin, _retrieve_class

from .operations.preparations import (
from .instructions.preparations import (
Vacuum,
Mean,
Covariance,
Expand All @@ -24,7 +24,7 @@
Annihilate,
)

from .operations.gates import (
from .instructions.gates import (
GaussianTransform,
Phaseshifter,
Beamsplitter,
Expand All @@ -44,7 +44,7 @@
Sampling,
)

from .operations.measurements import (
from .instructions.measurements import (
MeasureParticleNumber,
MeasureHomodyne,
MeasureHeterodyne,
Expand Down
38 changes: 19 additions & 19 deletions piquasso/_backends/fock/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class BaseFockCircuit(Circuit, abc.ABC):

def get_operation_map(self):
def get_instruction_map(self):
return {
"Interferometer": self._passive_linear,
"Beamsplitter": self._passive_linear,
Expand All @@ -25,42 +25,42 @@ def get_operation_map(self):
"Annihilate": self._annihilate,
}

def _passive_linear(self, operation):
def _passive_linear(self, instruction):
self.state._apply_passive_linear(
operator=operation._passive_representation,
modes=operation.modes
operator=instruction._passive_representation,
modes=instruction.modes
)

def _measure_particle_number(self, operation):
def _measure_particle_number(self, instruction):
outcomes = self.state._measure_particle_number(
modes=operation.modes,
shots=operation.params["shots"],
modes=instruction.modes,
shots=instruction.params["shots"],
)

self._add_result(
[
Result(operation=operation, outcome=outcome)
Result(instruction=instruction, outcome=outcome)
for outcome in outcomes
]
)

def _vacuum(self, operation):
def _vacuum(self, instruction):
self.state._apply_vacuum()

def _create(self, operation):
self.state._apply_creation_operator(operation.modes)
def _create(self, instruction):
self.state._apply_creation_operator(instruction.modes)

def _annihilate(self, operation):
self.state._apply_annihilation_operator(operation.modes)
def _annihilate(self, instruction):
self.state._apply_annihilation_operator(instruction.modes)

def _kerr(self, operation):
def _kerr(self, instruction):
self.state._apply_kerr(
**operation.params,
mode=operation.modes[0],
**instruction.params,
mode=instruction.modes[0],
)

def _cross_kerr(self, operation):
def _cross_kerr(self, instruction):
self.state._apply_cross_kerr(
**operation.params,
modes=operation.modes,
**instruction.params,
modes=instruction.modes,
)
8 changes: 4 additions & 4 deletions piquasso/_backends/fock/general/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@


class FockCircuit(BaseFockCircuit):
def get_operation_map(self):
def get_instruction_map(self):
return {
"DensityMatrix": self._density_matrix,
**super().get_operation_map()
**super().get_instruction_map()
}

def _density_matrix(self, operation):
self.state._add_occupation_number_basis(**operation.params)
def _density_matrix(self, instruction):
self.state._add_occupation_number_basis(**instruction.params)
8 changes: 4 additions & 4 deletions piquasso/_backends/fock/pnc/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@


class PNCFockCircuit(BaseFockCircuit):
def get_operation_map(self):
def get_instruction_map(self):
return {
"DensityMatrix": self._density_matrix,
**super().get_operation_map()
**super().get_instruction_map()
}

def _density_matrix(self, operation):
self.state._add_occupation_number_basis(**operation.params)
def _density_matrix(self, instruction):
self.state._add_occupation_number_basis(**instruction.params)
10 changes: 5 additions & 5 deletions piquasso/_backends/fock/pure/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@


class PureFockCircuit(BaseFockCircuit):
def get_operation_map(self):
def get_instruction_map(self):
return {
"StateVector": self._state_vector,
**super().get_operation_map()
**super().get_instruction_map()
}

def _state_vector(self, operation):
def _state_vector(self, instruction):
self.state._add_occupation_number_basis(
**operation.params,
modes=operation.modes,
**instruction.params,
modes=instruction.modes,
)
5 changes: 3 additions & 2 deletions piquasso/_backends/fock/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ def __init__(self, *, d, cutoff):
@classmethod
def from_number_preparations(cls, *, d, cutoff, number_preparations):
"""
NOTE: Here is a small coupling between :class:`Operation` and :class:`State`.
This is the only case (so far) where the user could specify operations directly.
NOTE: Here is a small coupling between :class:`Instruction` and :class:`State`.
This is the only case (so far) where the user could specify instructions
directly.
Is this needed?
"""
Expand Down
50 changes: 25 additions & 25 deletions piquasso/_backends/gaussian/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class GaussianCircuit(Circuit):

def get_operation_map(self):
def get_instruction_map(self):
return {
"Interferometer": self._passive_linear,
"Beamsplitter": self._passive_linear,
Expand All @@ -33,54 +33,54 @@ def get_operation_map(self):
"MeasureParticleNumber": self._measure_particle_number,
}

def _passive_linear(self, operation):
def _passive_linear(self, instruction):
self.state._apply_passive_linear(
operation._passive_representation,
operation.modes
instruction._passive_representation,
instruction.modes
)

def _linear(self, operation):
def _linear(self, instruction):
self.state._apply_linear(
P=operation._passive_representation,
A=operation._active_representation,
modes=operation.modes
P=instruction._passive_representation,
A=instruction._active_representation,
modes=instruction.modes
)

def _displacement(self, operation):
def _displacement(self, instruction):
self.state._apply_displacement(
**operation.params,
mode=operation.modes[0],
**instruction.params,
mode=instruction.modes[0],
)

def _measure_dyne(self, operation):
def _measure_dyne(self, instruction):
outcomes = self.state._apply_generaldyne_measurement(
**operation.params,
modes=operation.modes,
**instruction.params,
modes=instruction.modes,
)

self._add_result(
[
Result(operation=operation, outcome=outcome)
Result(instruction=instruction, outcome=outcome)
for outcome in outcomes
]
)

def _vacuum(self, operation):
def _vacuum(self, instruction):
self.state.reset()

def _mean(self, operation):
self.state.mean = operation.params["mean"]
def _mean(self, instruction):
self.state.mean = instruction.params["mean"]

def _covariance(self, operation):
self.state.cov = operation.params["cov"]
def _covariance(self, instruction):
self.state.cov = instruction.params["cov"]

def _measure_particle_number(self, operation):
def _measure_particle_number(self, instruction):
outcome = self.state._apply_particle_number_measurement(
cutoff=operation.params["cutoff"],
shots=operation.params["shots"],
modes=operation.modes,
cutoff=instruction.params["cutoff"],
shots=instruction.params["shots"],
modes=instruction.modes,
)

self._add_result(
Result(operation=operation, outcome=outcome)
Result(instruction=instruction, outcome=outcome)
)
14 changes: 7 additions & 7 deletions piquasso/_backends/sampling/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class SamplingCircuit(Circuit):
r"""A circuit for fast boson sampling."""

def get_operation_map(self):
def get_instruction_map(self):
return {
"Beamsplitter": self._passive_linear,
"Phaseshifter": self._passive_linear,
Expand All @@ -23,23 +23,23 @@ def get_operation_map(self):
"Interferometer": self._passive_linear,
}

def _passive_linear(self, operation):
def _passive_linear(self, instruction):
r"""Applies an interferometer to the circuit.
This can be interpreted as placing another interferometer in the network, just
before performing the sampling. This operation is realized by multiplying
before performing the sampling. This instruction is realized by multiplying
current effective interferometer matrix with new interferometer matrix.
Do note, that new interferometer matrix works as interferometer matrix on
qumodes (provided as the arguments) and as an identity on every other mode.
"""

self.state._apply_passive_linear(
operation._passive_representation,
operation.modes,
instruction._passive_representation,
instruction.modes,
)

def sampling(self, operation):
def sampling(self, instruction):
simulation_strategy = GeneralizedCliffordsSimulationStrategy(
self.state.interferometer
)
Expand All @@ -48,5 +48,5 @@ def sampling(self, operation):
initial_state = np.array(self.state.initial_state)
self.state.results = sampling_simulator.get_classical_simulation_results(
initial_state,
samples_number=operation.params["shots"]
samples_number=instruction.params["shots"]
)
Loading

0 comments on commit 00f4af7

Please sign in to comment.