Skip to content

Commit a3caf85

Browse files
authored
Merge pull request #1782 from qiboteam/encodings
Moving helper functions out of `models.encodings`
2 parents e53275a + ee5e4b0 commit a3caf85

File tree

7 files changed

+2543
-2439
lines changed

7 files changed

+2543
-2439
lines changed

doc/source/api-reference/qibo.rst

Lines changed: 68 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,13 @@ Data Encoders
221221

222222
We provide a family of algorithms that encode classical data into quantum circuits.
223223

224+
225+
Binary encoder
226+
""""""""""""""
227+
228+
.. autofunction:: qibo.models.encodings.binary_encoder
229+
230+
224231
Computational Basis Encoder
225232
"""""""""""""""""""""""""""
226233

@@ -253,6 +260,63 @@ For instance, the following two circuit generations are equivalent:
253260
.. autofunction:: qibo.models.encodings.comp_basis_encoder
254261

255262

263+
Dicke state
264+
"""""""""""
265+
266+
.. autofunction:: qibo.models.encodings.dicke_state
267+
268+
269+
Entangling layer
270+
""""""""""""""""
271+
272+
Generates a layer of nearest-neighbour two-qubit gates, assuming 1-dimensional connectivity.
273+
With the exception of :class:`qibo.gates.gates.GeneralizedfSim`,
274+
any of the two-qubit gates implemented in ``qibo`` can be selected to customize the entangling layer.
275+
If the chosen gate is parametrized, all phases are set to :math:`0.0`.
276+
Note that these phases can be updated a posterior by using
277+
:meth:`qibo.models.Circuit.set_parameters`.
278+
The possible choices of layer ``architecture`` are the following, in alphabetical order:
279+
``diagonal``, ``even_layer``, ``next_nearest``, ``pyramid``, ``odd_layer``, ``shifted``, ``v``, and ``x``.
280+
For instance, we show below an example of four of those architectures for ``nqubits = 6`` and ``entangling_gate = "CNOT"``.
281+
282+
283+
.. image:: ../_static/entangling_layer.png
284+
:width: 800
285+
:height: 450
286+
:align: center
287+
288+
289+
If ``closed_boundary`` is set to ``True``, then an extra gate is added connecting the last and the first qubit,
290+
with the last qubit as the control qubit and the first qubit as a target qubit.
291+
292+
293+
.. autofunction:: qibo.models.encodings.entangling_layer
294+
295+
296+
Greenberger-Horne-Zeilinger (GHZ) state
297+
"""""""""""""""""""""""""""""""""""""""
298+
299+
.. autofunction:: qibo.models.encodings.ghz_state
300+
301+
302+
Graph state
303+
"""""""""""
304+
305+
.. autofunction:: qibo.models.encodings.graph_state
306+
307+
308+
Fixed Hamming-weight Encoder
309+
""""""""""""""""""""""""""""
310+
311+
.. autofunction:: qibo.models.encodings.hamming_weight_encoder
312+
313+
314+
Permutation synthesis
315+
"""""""""""""""""""""
316+
317+
.. autofunction:: qibo.models.encodings.permutation_synthesis
318+
319+
256320
Phase Encoder
257321
"""""""""""""
258322

@@ -294,12 +358,6 @@ Sparse encoder
294358
.. autofunction:: qibo.models.encodings.sparse_encoder
295359

296360

297-
Binary encoder
298-
""""""""""""""
299-
300-
.. autofunction:: qibo.models.encodings.binary_encoder
301-
302-
303361
Unary Encoder
304362
"""""""""""""
305363

@@ -368,63 +426,15 @@ of the :math:`d`-dimensional array is sampled from a Gaussian distribution
368426
.. autofunction:: qibo.models.encodings.unary_encoder_random_gaussian
369427

370428

371-
Fixed Hamming-weight Encoder
372-
""""""""""""""""""""""""""""
373-
374-
.. autofunction:: qibo.models.encodings.hamming_weight_encoder
375-
376-
377-
Entangling layer
378-
""""""""""""""""
379-
380-
Generates a layer of nearest-neighbour two-qubit gates, assuming 1-dimensional connectivity.
381-
With the exception of :class:`qibo.gates.gates.GeneralizedfSim`,
382-
any of the two-qubit gates implemented in ``qibo`` can be selected to customize the entangling layer.
383-
If the chosen gate is parametrized, all phases are set to :math:`0.0`.
384-
Note that these phases can be updated a posterior by using
385-
:meth:`qibo.models.Circuit.set_parameters`.
386-
The possible choices of layer ``architecture`` are the following, in alphabetical order:
387-
``diagonal``, ``even_layer``, ``next_nearest``, ``pyramid``, ``odd_layer``, ``shifted``, ``v``, and ``x``.
388-
For instance, we show below an example of four of those architectures for ``nqubits = 6`` and ``entangling_gate = "CNOT"``.
389-
390-
391-
.. image:: ../_static/entangling_layer.png
392-
:width: 800
393-
:height: 450
394-
:align: center
395-
396-
397-
If ``closed_boundary`` is set to ``True``, then an extra gate is added connecting the last and the first qubit,
398-
with the last qubit as the control qubit and the first qubit as a target qubit.
399-
400-
401-
.. autofunction:: qibo.models.encodings.entangling_layer
402-
403-
404-
Greenberger-Horne-Zeilinger (GHZ) state
405-
"""""""""""""""""""""""""""""""""""""""
406-
407-
.. autofunction:: qibo.models.encodings.ghz_state
408-
409-
410-
Dicke state
411-
"""""""""""
412-
413-
.. autofunction:: qibo.models.encodings.dicke_state
414-
415-
416-
Graph state
417-
"""""""""""
429+
Up-to-Hamming-weight-:math:`k` Encoder
430+
""""""""""""""""""""""""""""""""""""""
418431

419-
.. autofunction:: qibo.models.encodings.graph_state
432+
.. autofunction:: qibo.models.encodings.up_to_k_hamming_weight_encoder
420433

421-
Permutation synthesis
422-
"""""""""""""""""""""
423-
424-
.. autofunction:: qibo.models.encodings.permutation_synthesis
425434

426435
.. _error-mitigation:
427436

437+
428438
Error Mitigation
429439
^^^^^^^^^^^^^^^^
430440

src/qibo/backends/_hamming_weight_operations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def _gray_code(self, initial_string):
121121
Returns:
122122
ndarray: All bitstrings with the same Hamming weight as ``initial_string``.
123123
"""
124-
from qibo.models.encodings import _ehrlich_algorithm # pylint: disable=C0415
124+
from qibo.models._encodings import _ehrlich_algorithm # pylint: disable=C0415
125125

126126
strings = _ehrlich_algorithm(initial_string, return_indices=False)
127127
strings = [list(string) for string in strings]

src/qibo/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
sparse_encoder,
1414
unary_encoder,
1515
unary_encoder_random_gaussian,
16+
up_to_k_hamming_weight_encoder,
1617
)
1718
from qibo.models.error_mitigation import CDR, ICS, ZNE, vnCDR
1819
from qibo.models.evolution import AdiabaticEvolution, StateEvolution

0 commit comments

Comments
 (0)