QFT main

This module is aimed to provide the user means to study the QFT and especially how entanglement changes during its execution using the Mermin evaluation.

qft.bit_value(n, k, base=2)[source]

Returns the value of the k \(^{th}\) digit of the integer n given in base base.

Example:
>>> bit_value(5, 0)
1
>>> bit_value(5, 1)
0
>>> bit_value(15, 0, base=10)
5
Parameters:
  • n (int) – Integer studied.
  • k (int) – Digit desired.
  • base (int) – Base in which n is studied.
Returns:

int – Value of the k \(^{th}\) digit of the integer n given in base base.

qft.periodic_state(l, r, nWires)[source]

Returns the periodic state \(|\varphi^{l,r}>\) of size \(2^{nWires}\). We have:

\(|\varphi^{l,r}> = \sum_{i=0}^{A-1}|l+ir>/sqrt(A)\) with \(A = floor((2^{nWires}-l)/r)+1\)

In this definition, l is the shift of the state, and r is the period of the state.

Example:

Since \(|\varphi^{1,5}> = (|1>+|6>+|11>)/sqrt(3)=(|0001>+|0110>+|1011>)/sqrt(3)\),

>>> periodic_state(1,5,4)
(0, 1/3*sqrt(3), 0, 0, 0, 0, 1/3*sqrt(3), 0, 0, 0, 0, 1/3*sqrt(3), 0, 0, 0, 0)
Parameters:
  • l (int) – The shift of the state.
  • r (int) – The period of the state.
  • nWires (int) – The size of the system (number of qubits).
Returns:

vector – The state defined by l, r and nWires according to the definition given above.

qft.qft_evaluate(states, verbose=False, file_name=None)[source]

Computes the Mermin Evaluation for each state in states.

Example:
>>> qft_evaluate([periodic_state(1,5,4)])
[1.33201398251237]
Parameters:
  • states (list[vector]) – The states after each step of the QFT.
  • verbose (bool) – If \(verbose\) then extra run information will be displayed in terminal.
  • file_name (str) – File name for the registration of the Mermin evaluation for each step of the algorithm, in csv format.
Returns:

any – Result of this function depends on file_name. If a file name is given \(qft_main\) returns None, otherwise, it returns an array with the evaluation values.

qft.qft_layers(state)[source]

Computes the circuit for the QFT using the circuit format used for the run function from run_circuit.sage.

Example:
>>> qft_layers(periodic_state(2,1,3))
[
  [
    [ 1/2*sqrt(2)  1/2*sqrt(2)]  [1 0]  [1 0]
    [ 1/2*sqrt(2) -1/2*sqrt(2)], [0 1], [0 1]
  ],[
    [1 0 0 0 0 0 0 0]
    [0 1 0 0 0 0 0 0]
    [0 0 1 0 0 0 0 0]
    [0 0 0 1 0 0 0 0]
    [0 0 0 0 1 0 0 0]
    [0 0 0 0 0 1 0 0]
    [0 0 0 0 0 0 I 0]
    [0 0 0 0 0 0 0 I]
  ],[
    [1 0 0 0 0                     0 0                     0]
    [0 1 0 0 0                     0 0                     0]
    [0 0 1 0 0                     0 0                     0]
    [0 0 0 1 0                     0 0                     0]
    [0 0 0 0 1                     0 0                     0]
    [0 0 0 0 0 (1/2*I + 1/2)*sqrt(2) 0                     0]
    [0 0 0 0 0                     0 1                     0]
    [0 0 0 0 0                     0 0 (1/2*I + 1/2)*sqrt(2)]
  ],[
    [1 0]  [ 1/2*sqrt(2)  1/2*sqrt(2)]  [1 0]
    [0 1], [ 1/2*sqrt(2) -1/2*sqrt(2)], [0 1]
  ],[
    [1 0 0 0 0 0 0 0]
    [0 1 0 0 0 0 0 0]
    [0 0 1 0 0 0 0 0]
    [0 0 0 I 0 0 0 0]
    [0 0 0 0 1 0 0 0]
    [0 0 0 0 0 1 0 0]
    [0 0 0 0 0 0 1 0]
    [0 0 0 0 0 0 0 I]
  ],[
    [1 0]  [1 0]  [ 1/2*sqrt(2)  1/2*sqrt(2)]
    [0 1], [0 1], [ 1/2*sqrt(2) -1/2*sqrt(2)]
  ],[
    [1 0 0 0 0 0 0 0]
    [0 0 0 0 1 0 0 0]
    [0 0 1 0 0 0 0 0]
    [0 0 0 0 0 0 1 0]
    [0 1 0 0 0 0 0 0]
    [0 0 0 0 0 1 0 0]
    [0 0 0 1 0 0 0 0]
    [0 0 0 0 0 0 0 1]
  ]
]
Parameters:state (vector[int]) – State on which the operator wants the QFT performed of, this is usually a periodic state.
Returns:(list[list[matrix]],int) – Circuit for the QFT.
qft.qft_main(state, verbose=False, file_name=None)[source]

Prints in terminal or in file file_name the Mermin evaluation of each step of the QFT.

Example:
>>> grover(periodic_state(0,11,4))0,1.99823485241887
1.99933058720672
1.99761683801972
1.84600827724524
1.66149864543535
1.66010335826574
1.66127978203391
2.17163453049907
2.17187381801221
1.54230165695219
1.54129902140376
1.54169705834015
Parameters:
  • state (vector[int]) – State on which the operator wants the QFT performed of, this is usually a periodic state.
  • verbose (bool) – If verbose then extra run information will be displayed in terminal.
  • file_name (str) – File name for the registration of the Mermin evaluation for each step of the algorithm, in csv format.
Returns:

any – Result of this function depends on file_name. If a file name is given \(qft_main\) returns None, otherwise, it returns an array with the evaluation values .

qft.qft_matrix(size)[source]

This function should compute a matrix equivalent to the whole QFT operation. It has not been tester much though and should not be relied on for now.

Example:
>>> qft_matrix(3)
[   1/4*sqrt(2)    1/4*sqrt(2)    1/4*sqrt(2)    1/4*sqrt(2)    1/4*sqrt(2)    1/4*sqrt(2)    1/4*sqrt(2)    1/4*sqrt(2)]
[   1/4*sqrt(2)    1/4*I + 1/4  1/4*I*sqrt(2)    1/4*I - 1/4   -1/4*sqrt(2)   -1/4*I - 1/4 -1/4*I*sqrt(2)   -1/4*I + 1/4]
[   1/4*sqrt(2)  1/4*I*sqrt(2)   -1/4*sqrt(2) -1/4*I*sqrt(2)    1/4*sqrt(2)  1/4*I*sqrt(2)   -1/4*sqrt(2) -1/4*I*sqrt(2)]
[   1/4*sqrt(2)    1/4*I - 1/4 -1/4*I*sqrt(2)    1/4*I + 1/4   -1/4*sqrt(2)   -1/4*I + 1/4  1/4*I*sqrt(2)   -1/4*I - 1/4]
[   1/4*sqrt(2)   -1/4*sqrt(2)    1/4*sqrt(2)   -1/4*sqrt(2)    1/4*sqrt(2)   -1/4*sqrt(2)    1/4*sqrt(2)   -1/4*sqrt(2)]
[   1/4*sqrt(2)   -1/4*I - 1/4  1/4*I*sqrt(2)   -1/4*I + 1/4   -1/4*sqrt(2)    1/4*I + 1/4 -1/4*I*sqrt(2)    1/4*I - 1/4]
[   1/4*sqrt(2) -1/4*I*sqrt(2)   -1/4*sqrt(2)  1/4*I*sqrt(2)    1/4*sqrt(2) -1/4*I*sqrt(2)   -1/4*sqrt(2)  1/4*I*sqrt(2)]
[   1/4*sqrt(2)   -1/4*I + 1/4 -1/4*I*sqrt(2)   -1/4*I - 1/4   -1/4*sqrt(2)    1/4*I - 1/4  1/4*I*sqrt(2)    1/4*I + 1/4]
Parameters:size (int) – The size of the QFT (number of qubits).
Returns:matrix – The matrix corresponding to the QFT.
qft.qft_run(state, verbose=False)[source]

Runs a simulation of the QFT.

Example:
>>> qft_run(periodic_state(2,1,3))
[(0, 0, 1/6*sqrt(6), 1/6*sqrt(6), 1/6*sqrt(6), 1/6*sqrt(6), 1/6*sqrt(6), 1/6*sqrt(6)),
 (1/12*sqrt(6)*sqrt(2), 1/12*sqrt(6)*sqrt(2), 1/6*sqrt(6)*sqrt(2), 1/6*sqrt(6)*sqrt(2), -1/12*sqrt(6)*sqrt(2), -1/12*sqrt(6)*sqrt(2), 0, 0),
 (1/12*sqrt(6)*sqrt(2), 1/12*sqrt(6)*sqrt(2), 1/6*sqrt(6)*sqrt(2), 1/6*sqrt(6)*sqrt(2), -1/12*sqrt(6)*sqrt(2), -1/12*sqrt(6)*sqrt(2), 0, 0),
 (1/12*sqrt(6)*sqrt(2), 1/12*sqrt(6)*sqrt(2), 1/6*sqrt(6)*sqrt(2), 1/6*sqrt(6)*sqrt(2), -1/12*sqrt(6)*sqrt(2), -(1/12*I + 1/12)*sqrt(6), 0, 0),
 (1/4*sqrt(6), 1/4*sqrt(6), -1/12*sqrt(6), -1/12*sqrt(6), -1/12*sqrt(6), -(1/24*I + 1/24)*sqrt(6)*sqrt(2), -1/12*sqrt(6), -(1/24*I + 1/24)*sqrt(6)*sqrt(2)),
 (1/4*sqrt(6), 1/4*sqrt(6), -1/12*sqrt(6), -1/12*I*sqrt(6), -1/12*sqrt(6), -(1/24*I + 1/24)*sqrt(6)*sqrt(2), -1/12*sqrt(6), -(1/24*I - 1/24)*sqrt(6)*sqrt(2)),
 (1/4*sqrt(6)*sqrt(2), 0, -(1/24*I + 1/24)*sqrt(6)*sqrt(2), (1/24*I - 1/24)*sqrt(6)*sqrt(2), -1/24*sqrt(6)*sqrt(2) - (1/24*I + 1/24)*sqrt(6), -1/24*sqrt(6)*sqrt(2) + (1/24*I + 1/24)*sqrt(6), -1/24*sqrt(6)*sqrt(2) - (1/24*I - 1/24)*sqrt(6), -1/24*sqrt(6)*sqrt(2) + (1/24*I - 1/24)*sqrt(6)),
 (1/4*sqrt(6)*sqrt(2), -1/24*sqrt(6)*sqrt(2) - (1/24*I + 1/24)*sqrt(6), -(1/24*I + 1/24)*sqrt(6)*sqrt(2), -1/24*sqrt(6)*sqrt(2) - (1/24*I - 1/24)*sqrt(6), 0, -1/24*sqrt(6)*sqrt(2) + (1/24*I + 1/24)*sqrt(6), (1/24*I - 1/24)*sqrt(6)*sqrt(2), -1/24*sqrt(6)*sqrt(2) + (1/24*I - 1/24)*sqrt(6))]
Parameters:
  • state (vector[int]) – State on which the operator wants the QFT performed of, this is usually a periodic state.
  • verbose (bool) – If verbose then extra run information will be displayed in terminal.
Returns:

list[vectors] – the list of states after each step.

qft.set_bit_value(n, k, value, base=2)[source]

Returns n with its k \(^{th}\) bit set to value in base base.

Example:
>>> set_bit_value(5, 0, 0)
4
>>> set_bit_value(5, 1, 0)
5
>>> set_bit_value(15, 0, 9, base=10)
19
Parameters:
  • n (int) – Integer modified.
  • k (int) – Digit to change.
  • value (int) – Value wanted for the k \(^{th}\) digit of n (must be between 0 and base-1).
  • base (int) – Base in which n is modified.
Returns:

int – n with its k \(^{th}\) bit set to value in base base.