Skip to content

Commit 78894a5

Browse files
github-actionsgithub-actions
github-actions
authored and
github-actions
committed
fixup! Format Python code with psf/black push
1 parent 0af1d0f commit 78894a5

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

quantum/deutsch_jozsa.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,28 @@ def dj_oracle(case: str, n: int):
1515
# We need to make a QuantumCircuit object to return
1616
# This circuit has n+1 qubits: the size of the input,
1717
# plus one output qubit
18-
oracle_qc = q.QuantumCircuit(n+1)
19-
18+
oracle_qc = q.QuantumCircuit(n + 1)
19+
2020
# First, let's deal with the case in which oracle is balanced
2121
if case == "balanced":
2222
# First generate a random number that tells us which CNOTs to
2323
# wrap in X-gates:
24-
b = np.random.randint(1,2**n)
24+
b = np.random.randint(1, 2 ** n)
2525
# Next, format 'b' as a binary string of length 'n', padded with zeros:
26-
b_str = format(b, '0'+str(n)+'b')
27-
# Next, we place the first X-gates. Each digit in our binary string
26+
b_str = format(b, "0" + str(n) + "b")
27+
# Next, we place the first X-gates. Each digit in our binary string
2828
# correspopnds to a qubit, if the digit is 0, we do nothing, if it's 1
2929
# we apply an X-gate to that qubit:
3030
for qubit in range(len(b_str)):
31-
if b_str[qubit] == '1':
31+
if b_str[qubit] == "1":
3232
oracle_qc.x(qubit)
33-
# Do the controlled-NOT gates for each qubit, using the output qubit
33+
# Do the controlled-NOT gates for each qubit, using the output qubit
3434
# as the target:
3535
for qubit in range(n):
3636
oracle_qc.cx(qubit, n)
3737
# Next, place the final X-gates
3838
for qubit in range(len(b_str)):
39-
if b_str[qubit] == '1':
39+
if b_str[qubit] == "1":
4040
oracle_qc.x(qubit)
4141

4242
# Case in which oracle is constant
@@ -46,29 +46,29 @@ def dj_oracle(case: str, n: int):
4646
output = np.random.randint(2)
4747
if output == 1:
4848
oracle_qc.x(n)
49-
49+
5050
oracle_gate = oracle_qc.to_gate()
51-
oracle_gate.name = "Oracle" # To show when we display the circuit
51+
oracle_gate.name = "Oracle" # To show when we display the circuit
5252
return oracle_gate
5353

5454

5555
def dj_algorithm(oracle, n: int):
56-
dj_circuit = q.QuantumCircuit(n+1, n)
56+
dj_circuit = q.QuantumCircuit(n + 1, n)
5757
# Set up the output qubit:
5858
dj_circuit.x(n)
5959
dj_circuit.h(n)
6060
# And set up the input register:
6161
for qubit in range(n):
6262
dj_circuit.h(qubit)
6363
# Let's append the oracle gate to our circuit:
64-
dj_circuit.append(oracle, range(n+1))
64+
dj_circuit.append(oracle, range(n + 1))
6565
# Finally, perform the H-gates again and measure:
6666
for qubit in range(n):
6767
dj_circuit.h(qubit)
68-
68+
6969
for i in range(n):
7070
dj_circuit.measure(i, i)
71-
71+
7272
return dj_circuit
7373

7474

0 commit comments

Comments
 (0)