Skip to content

Commit 3bee274

Browse files
committed
update week 11
1 parent f6a2615 commit 3bee274

23 files changed

+173
-291
lines changed

doc/pub/week11/html/week11-bs.html

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ <h2 id="applying-to-all-qubits" class="anchor">Applying to all qubits </h2>
10241024

10251025
<!-- !split -->
10261026
<h2 id="qft-example-codes" class="anchor">QFT example codes </h2>
1027-
1027+
<p>This code sets up the QFT for \( n \) qubits.</p>
10281028

10291029
<!-- code=text (!bc pycode) typeset with pygments style "default" -->
10301030
<div class="cell border-box-sizing code_cell rendered">
@@ -1034,39 +1034,22 @@ <h2 id="qft-example-codes" class="anchor">QFT example codes </h2>
10341034
<div class="highlight" style="background: #f8f8f8">
10351035
<pre style="line-height: 125%;">import numpy as np
10361036
def qft(n):
1037-
Creates the Quantum Fourier Transform (QFT) matrix for n qubits.
1038-
1039-
Parameters:
1040-
- n: Number of qubits (QFT acts on 2^n dimensions)
10411037

1042-
Returns:
1043-
- QFT matrix of size (2^n, 2^n)
1044-
&quot;&quot;&quot;
1038+
# Inputs n qubits and returns QFT matrix of size (2^n, 2^n)
10451039
dim = 2 ** n # Dimension of the Hilbert space
10461040
omega = np.exp(2j * np.pi / dim) # Primitive root of unity
1047-
10481041
# Initialize QFT matrix
10491042
QFT = np.zeros((dim, dim), dtype=complex)
1050-
10511043
# Construct the QFT matrix
10521044
for i in range(dim):
10531045
for j in range(dim):
10541046
QFT[i, j] = omega ** (i * j) / np.sqrt(dim)
1055-
10561047
return QFT
10571048

10581049
def apply_qft(state):
1059-
&quot;&quot;&quot;
1060-
Applies QFT to a given quantum state vector.
1061-
Parameters:
1062-
- state: Input state vector (1D NumPy array)
1063-
Returns:
1064-
- Transformed state vector after QFT
1065-
&quot;&quot;&quot;
10661050
n = int(np.log2(len(state))) # Number of qubits
10671051
qft_matrix = qft(n)
1068-
return np.dot(qft_matrix, state)
1069-
1052+
return qft_matrix @ state
10701053
# Example: 3-qubit system
10711054
n_qubits = 3 # QFT on 3 qubits (8 dimensions)
10721055
dim = 2 ** n_qubits

doc/pub/week11/html/week11-reveal.html

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,7 @@ <h2 id="applying-to-all-qubits">Applying to all qubits </h2>
10311031

10321032
<section>
10331033
<h2 id="qft-example-codes">QFT example codes </h2>
1034-
1034+
<p>This code sets up the QFT for \( n \) qubits.</p>
10351035

10361036
<!-- code=text (!bc pycode) typeset with pygments style "perldoc" -->
10371037
<div class="cell border-box-sizing code_cell rendered">
@@ -1041,39 +1041,22 @@ <h2 id="qft-example-codes">QFT example codes </h2>
10411041
<div class="highlight" style="background: #eeeedd">
10421042
<pre style="font-size: 80%; line-height: 125%;">import numpy as np
10431043
def qft(n):
1044-
Creates the Quantum Fourier Transform (QFT) matrix for n qubits.
1045-
1046-
Parameters:
1047-
- n: Number of qubits (QFT acts on 2^n dimensions)
10481044

1049-
Returns:
1050-
- QFT matrix of size (2^n, 2^n)
1051-
&quot;&quot;&quot;
1045+
# Inputs n qubits and returns QFT matrix of size (2^n, 2^n)
10521046
dim = 2 ** n # Dimension of the Hilbert space
10531047
omega = np.exp(2j * np.pi / dim) # Primitive root of unity
1054-
10551048
# Initialize QFT matrix
10561049
QFT = np.zeros((dim, dim), dtype=complex)
1057-
10581050
# Construct the QFT matrix
10591051
for i in range(dim):
10601052
for j in range(dim):
10611053
QFT[i, j] = omega ** (i * j) / np.sqrt(dim)
1062-
10631054
return QFT
10641055

10651056
def apply_qft(state):
1066-
&quot;&quot;&quot;
1067-
Applies QFT to a given quantum state vector.
1068-
Parameters:
1069-
- state: Input state vector (1D NumPy array)
1070-
Returns:
1071-
- Transformed state vector after QFT
1072-
&quot;&quot;&quot;
10731057
n = int(np.log2(len(state))) # Number of qubits
10741058
qft_matrix = qft(n)
1075-
return np.dot(qft_matrix, state)
1076-
1059+
return qft_matrix @ state
10771060
# Example: 3-qubit system
10781061
n_qubits = 3 # QFT on 3 qubits (8 dimensions)
10791062
dim = 2 ** n_qubits

doc/pub/week11/html/week11-solarized.html

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,7 @@ <h2 id="applying-to-all-qubits">Applying to all qubits </h2>
959959

960960
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
961961
<h2 id="qft-example-codes">QFT example codes </h2>
962-
962+
<p>This code sets up the QFT for \( n \) qubits.</p>
963963

964964
<!-- code=text (!bc pycode) typeset with pygments style "perldoc" -->
965965
<div class="cell border-box-sizing code_cell rendered">
@@ -969,39 +969,22 @@ <h2 id="qft-example-codes">QFT example codes </h2>
969969
<div class="highlight" style="background: #eeeedd">
970970
<pre style="line-height: 125%;">import numpy as np
971971
def qft(n):
972-
Creates the Quantum Fourier Transform (QFT) matrix for n qubits.
973-
974-
Parameters:
975-
- n: Number of qubits (QFT acts on 2^n dimensions)
976972

977-
Returns:
978-
- QFT matrix of size (2^n, 2^n)
979-
&quot;&quot;&quot;
973+
# Inputs n qubits and returns QFT matrix of size (2^n, 2^n)
980974
dim = 2 ** n # Dimension of the Hilbert space
981975
omega = np.exp(2j * np.pi / dim) # Primitive root of unity
982-
983976
# Initialize QFT matrix
984977
QFT = np.zeros((dim, dim), dtype=complex)
985-
986978
# Construct the QFT matrix
987979
for i in range(dim):
988980
for j in range(dim):
989981
QFT[i, j] = omega ** (i * j) / np.sqrt(dim)
990-
991982
return QFT
992983

993984
def apply_qft(state):
994-
&quot;&quot;&quot;
995-
Applies QFT to a given quantum state vector.
996-
Parameters:
997-
- state: Input state vector (1D NumPy array)
998-
Returns:
999-
- Transformed state vector after QFT
1000-
&quot;&quot;&quot;
1001985
n = int(np.log2(len(state))) # Number of qubits
1002986
qft_matrix = qft(n)
1003-
return np.dot(qft_matrix, state)
1004-
987+
return qft_matrix @ state
1005988
# Example: 3-qubit system
1006989
n_qubits = 3 # QFT on 3 qubits (8 dimensions)
1007990
dim = 2 ** n_qubits

doc/pub/week11/html/week11.html

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ <h2 id="applying-to-all-qubits">Applying to all qubits </h2>
10361036

10371037
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
10381038
<h2 id="qft-example-codes">QFT example codes </h2>
1039-
1039+
<p>This code sets up the QFT for \( n \) qubits.</p>
10401040

10411041
<!-- code=text (!bc pycode) typeset with pygments style "default" -->
10421042
<div class="cell border-box-sizing code_cell rendered">
@@ -1046,39 +1046,22 @@ <h2 id="qft-example-codes">QFT example codes </h2>
10461046
<div class="highlight" style="background: #f8f8f8">
10471047
<pre style="line-height: 125%;">import numpy as np
10481048
def qft(n):
1049-
Creates the Quantum Fourier Transform (QFT) matrix for n qubits.
1050-
1051-
Parameters:
1052-
- n: Number of qubits (QFT acts on 2^n dimensions)
10531049

1054-
Returns:
1055-
- QFT matrix of size (2^n, 2^n)
1056-
&quot;&quot;&quot;
1050+
# Inputs n qubits and returns QFT matrix of size (2^n, 2^n)
10571051
dim = 2 ** n # Dimension of the Hilbert space
10581052
omega = np.exp(2j * np.pi / dim) # Primitive root of unity
1059-
10601053
# Initialize QFT matrix
10611054
QFT = np.zeros((dim, dim), dtype=complex)
1062-
10631055
# Construct the QFT matrix
10641056
for i in range(dim):
10651057
for j in range(dim):
10661058
QFT[i, j] = omega ** (i * j) / np.sqrt(dim)
1067-
10681059
return QFT
10691060

10701061
def apply_qft(state):
1071-
&quot;&quot;&quot;
1072-
Applies QFT to a given quantum state vector.
1073-
Parameters:
1074-
- state: Input state vector (1D NumPy array)
1075-
Returns:
1076-
- Transformed state vector after QFT
1077-
&quot;&quot;&quot;
10781062
n = int(np.log2(len(state))) # Number of qubits
10791063
qft_matrix = qft(n)
1080-
return np.dot(qft_matrix, state)
1081-
1064+
return qft_matrix @ state
10821065
# Example: 3-qubit system
10831066
n_qubits = 3 # QFT on 3 qubits (8 dimensions)
10841067
dim = 2 ** n_qubits
1 Byte
Binary file not shown.

0 commit comments

Comments
 (0)