Skip to content

Commit c818db8

Browse files
github-actionsgithub-actions
authored andcommitted
fixup! Format Python code with psf/black push
1 parent 1a33ec4 commit c818db8

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

quantum/deutsch_jozsa.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,28 @@ def dj_oracle(case: str, num_qubits: int) -> q.QuantumCircuit:
3333
"""
3434
# This circuit has num_qubits+1 qubits: the size of the input,
3535
# plus one output qubit
36-
oracle_qc = q.QuantumCircuit(num_qubits+1)
37-
36+
oracle_qc = q.QuantumCircuit(num_qubits + 1)
37+
3838
# First, let's deal with the case in which oracle is balanced
3939
if case == "balanced":
4040
# First generate a random number that tells us which CNOTs to
4141
# wrap in X-gates:
42-
b = np.random.randint(1,2**num_qubits)
42+
b = np.random.randint(1, 2 ** num_qubits)
4343
# Next, format 'b' as a binary string of length 'n', padded with zeros:
44-
b_str = format(b, f"0{num_qubits}b")
45-
# Next, we place the first X-gates. Each digit in our binary string
44+
b_str = format(b, f"0{num_qubits}b")
45+
# Next, we place the first X-gates. Each digit in our binary string
4646
# correspopnds to a qubit, if the digit is 0, we do nothing, if it's 1
4747
# we apply an X-gate to that qubit:
4848
for index, bit in enumerate(b_str):
49-
if bit == '1':
49+
if bit == "1":
5050
oracle_qc.x(index)
51-
# Do the controlled-NOT gates for each qubit, using the output qubit
51+
# Do the controlled-NOT gates for each qubit, using the output qubit
5252
# as the target:
5353
for index in range(num_qubits):
5454
oracle_qc.cx(index, num_qubits)
5555
# Next, place the final X-gates
5656
for index, bit in enumerate(b_str):
57-
if bit == '1':
57+
if bit == "1":
5858
oracle_qc.x(index)
5959

6060
# Case in which oracle is constant
@@ -64,40 +64,40 @@ def dj_oracle(case: str, num_qubits: int) -> q.QuantumCircuit:
6464
output = np.random.randint(2)
6565
if output == 1:
6666
oracle_qc.x(num_qubits)
67-
67+
6868
oracle_gate = oracle_qc.to_gate()
69-
oracle_gate.name = "Oracle" # To show when we display the circuit
69+
oracle_gate.name = "Oracle" # To show when we display the circuit
7070
return oracle_gate
7171

7272

7373
def dj_algorithm(oracle: q.QuantumCircuit, num_qubits: int) -> q.QuantumCircuit:
7474
"""
7575
Returns the complete Deustch-Jozsa Quantum Circuit,
76-
adding Input & Output registers and Hadamard & Measurement Gates,
76+
adding Input & Output registers and Hadamard & Measurement Gates,
7777
to the Oracle Circuit passed in arguments
7878
"""
79-
dj_circuit = q.QuantumCircuit(num_qubits+1, num_qubits)
79+
dj_circuit = q.QuantumCircuit(num_qubits + 1, num_qubits)
8080
# Set up the output qubit:
8181
dj_circuit.x(num_qubits)
8282
dj_circuit.h(num_qubits)
8383
# And set up the input register:
8484
for qubit in range(num_qubits):
8585
dj_circuit.h(qubit)
8686
# Let's append the oracle gate to our circuit:
87-
dj_circuit.append(oracle, range(num_qubits+1))
87+
dj_circuit.append(oracle, range(num_qubits + 1))
8888
# Finally, perform the H-gates again and measure:
8989
for qubit in range(num_qubits):
9090
dj_circuit.h(qubit)
91-
91+
9292
for i in range(num_qubits):
9393
dj_circuit.measure(i, i)
94-
94+
9595
return dj_circuit
9696

9797

9898
def deutsch_jozsa(case: str, num_qubits: int) -> q.result.counts.Counts:
9999
"""
100-
Main function that builds the circuit using other helper functions,
100+
Main function that builds the circuit using other helper functions,
101101
runs the experiment 1000 times & returns the resultant qubit counts
102102
>>> deutsch_jozsa("constant", 3)
103103
{'000': 1000}

0 commit comments

Comments
 (0)