Skip to content

Commit

Permalink
Blacken stragglers (#6611)
Browse files Browse the repository at this point in the history
* Blacken stragglers

* fix tox.ini and azure-pipelines.yml

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
levbishop and mergify[bot] authored Jun 21, 2021
1 parent 50c30f5 commit 9e9ad8a
Show file tree
Hide file tree
Showing 20 changed files with 167 additions and 133 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ env:
# Ignoring generated ones with .py extension.
lint:
pylint -rn qiskit test
tools/verify_headers.py qiskit test tools
tools/verify_headers.py qiskit test tools examples
pylint -rn --disable='C0103, C0114, W0621' examples/python/*.py
python tools/find_optional_imports.py
tools/find_optional_imports.py

style:
black --check qiskit test tools
black --check qiskit test tools examples setup.py

black:
black qiskit test tools
black qiskit test tools examples setup.py

# Use the -s (starting directory) flag for "unittest discover" is necessary,
# otherwise the QuantumCircuit header will be modified during the discovery.
Expand Down
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ stages:
- bash: |
set -e
source test-job/bin/activate
black --check qiskit test tools
black --check qiskit test tools examples setup.py
pylint -rn qiskit test
tools/verify_headers.py qiskit test
python tools/find_optional_imports.py
Expand Down
65 changes: 32 additions & 33 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,20 @@
"""

import os

# Set env flag so that we can doc functions that may otherwise not be loaded
# see for example interactive visualizations in qiskit.visualization.
os.environ['QISKIT_DOCS'] = 'TRUE'
os.environ["QISKIT_DOCS"] = "TRUE"

# -- Project information -----------------------------------------------------
project = 'Qiskit'
copyright = '2019, Qiskit Development Team' # pylint: disable=redefined-builtin
author = 'Qiskit Development Team'
project = "Qiskit"
copyright = "2019, Qiskit Development Team" # pylint: disable=redefined-builtin
author = "Qiskit Development Team"

# The short X.Y version
version = ''
version = ""
# The full version, including alpha/beta/rc tags
release = '0.18.0'
release = "0.18.0"

# -- General configuration ---------------------------------------------------

Expand All @@ -56,19 +57,19 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.napoleon',
'sphinx.ext.autodoc',
'sphinx.ext.autosummary',
'sphinx.ext.mathjax',
'sphinx.ext.viewcode',
'sphinx.ext.extlinks',
'jupyter_sphinx',
'sphinx_autodoc_typehints',
'reno.sphinxext',
'sphinx_panels',
"sphinx.ext.napoleon",
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx.ext.mathjax",
"sphinx.ext.viewcode",
"sphinx.ext.extlinks",
"jupyter_sphinx",
"sphinx_autodoc_typehints",
"reno.sphinxext",
"sphinx_panels",
]
html_static_path = ['_static']
templates_path = ['_templates']
html_static_path = ["_static"]
templates_path = ["_templates"]
html_css_files = []

# -----------------------------------------------------------------------------
Expand All @@ -83,7 +84,7 @@
# -----------------------------------------------------------------------------

autodoc_default_options = {
'inherited-members': None,
"inherited-members": None,
}


Expand All @@ -94,9 +95,7 @@
# A dictionary mapping 'figure', 'table', 'code-block' and 'section' to
# strings that are used for format of figure numbers. As a special character,
# %s will be replaced to figure number.
numfig_format = {
'table': 'Table %s'
}
numfig_format = {"table": "Table %s"}
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
Expand All @@ -107,10 +106,10 @@
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', '**.ipynb_checkpoints']
exclude_patterns = ["_build", "**.ipynb_checkpoints"]

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'colorful'
pygments_style = "colorful"

# A boolean that decides whether module names are prepended to all object names
# (for object types where a “module” of some kind is defined), e.g. for
Expand All @@ -121,7 +120,7 @@
# (e.g., if this is set to ['foo.'], then foo.bar is shown under B, not F).
# This can be handy if you document a project that consists of a single
# package. Works only for the HTML builder currently.
modindex_common_prefix = ['qiskit.']
modindex_common_prefix = ["qiskit."]

# -- Configuration for extlinks extension ------------------------------------
# Refer to https://www.sphinx-doc.org/en/master/usage/extensions/extlinks.html
Expand All @@ -132,16 +131,16 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'qiskit_sphinx_theme' # use the theme in subdir 'theme'
html_theme = "qiskit_sphinx_theme" # use the theme in subdir 'theme'

#html_sidebars = {'**': ['globaltoc.html']}
html_last_updated_fmt = '%Y/%m/%d'
# html_sidebars = {'**': ['globaltoc.html']}
html_last_updated_fmt = "%Y/%m/%d"

html_theme_options = {
'logo_only': True,
'display_version': True,
'prev_next_buttons_location': 'bottom',
'style_external_links': True,
"logo_only": True,
"display_version": True,
"prev_next_buttons_location": "bottom",
"style_external_links": True,
}

autoclass_content = 'both'
autoclass_content = "both"
1 change: 1 addition & 0 deletions examples/python/circuit_draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def build_bell_circuit():
qc.measure([0, 1], [0, 1])
return qc


# Create the circuit
bell_circuit = build_bell_circuit()

Expand Down
10 changes: 5 additions & 5 deletions examples/python/ghz.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@
# Make a quantum circuit for the GHZ state.
###############################################################
num_qubits = 5
qc = QuantumCircuit(num_qubits, num_qubits, name='ghz')
qc = QuantumCircuit(num_qubits, num_qubits, name="ghz")

# Create a GHZ state
qc.h(0)
for i in range(num_qubits-1):
qc.cx(i, i+1)
for i in range(num_qubits - 1):
qc.cx(i, i + 1)
# Insert a barrier before measurement
qc.barrier()
# Measure all of the qubits in the standard basis
for i in range(num_qubits):
qc.measure(i, i)

sim_backend = BasicAer.get_backend('qasm_simulator')
sim_backend = BasicAer.get_backend("qasm_simulator")
job = execute(qc, sim_backend, shots=1024)
result = job.result()
print('Qasm simulator : ')
print("Qasm simulator : ")
print(result.get_counts(qc))
12 changes: 6 additions & 6 deletions examples/python/ibmq/ghz.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
# Make a quantum circuit for the GHZ state.
###############################################################
num_qubits = 5
qc = QuantumCircuit(num_qubits, num_qubits, name='ghz')
qc = QuantumCircuit(num_qubits, num_qubits, name="ghz")

# Create a GHZ state
qc.h(0)
for i in range(num_qubits-1):
qc.cx(i, i+1)
for i in range(num_qubits - 1):
qc.cx(i, i + 1)
# Insert a barrier before measurement
qc.barrier()
# Measure all of the qubits in the standard basis
Expand All @@ -41,10 +41,10 @@

# Second version: real device
least_busy_device = least_busy(
provider.backends(simulator=False,
filters=lambda x: x.configuration().n_qubits > 4))
provider.backends(simulator=False, filters=lambda x: x.configuration().n_qubits > 4)
)
print("Running on current least busy device: ", least_busy_device)
job = execute(qc, least_busy_device, shots=1024)
result = job.result()
print('Physical device (%s) : ' % least_busy_device)
print("Physical device (%s) : " % least_busy_device)
print(result.get_counts(qc))
17 changes: 10 additions & 7 deletions examples/python/ibmq/hello_quantum.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

# See a list of available local simulators
print("BasicAer backends: ", BasicAer.backends())
backend_sim = BasicAer.get_backend('qasm_simulator')
backend_sim = BasicAer.get_backend("qasm_simulator")

# Compile and run the Quantum circuit on a simulator backend
job_sim = execute(qc, backend_sim)
Expand All @@ -43,9 +43,11 @@
try:
provider = IBMQ.load_account()
except:
print("""WARNING: No valid IBMQ credentials found on disk.
print(
"""WARNING: No valid IBMQ credentials found on disk.
You must store your credentials using IBMQ.save_account(token, url).
For now, there's only access to local simulator backends...""")
For now, there's only access to local simulator backends..."""
)
exit(0)

# see a list of available remote backends
Expand All @@ -55,16 +57,17 @@
# Compile and run the Quantum Program on a real device backend
# select those with at least 2 qubits
try:
least_busy_device = least_busy(provider.backends(
filters=lambda x: x.configuration().n_qubits >= 2, simulator=False))
least_busy_device = least_busy(
provider.backends(filters=lambda x: x.configuration().n_qubits >= 2, simulator=False)
)
except:
print("All devices are currently unavailable.")

print("Running on current least busy device: ", least_busy_device)

#running the job
# running the job
job_exp = execute(qc, least_busy_device, shots=1024, max_credits=10)
result_exp = job_exp.result()

# Show the results
print('Counts: ', result_exp.get_counts(qc))
print("Counts: ", result_exp.get_counts(qc))
8 changes: 4 additions & 4 deletions examples/python/ibmq/qft.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ def input_state(circ, n):
"""n-qubit input state for QFT that produces output 1."""
for j in range(n):
circ.h(j)
circ.p(-math.pi/float(2**(j)), j)
circ.p(-math.pi / float(2 ** (j)), j)


def qft(circ, n):
"""n-qubit QFT on q in circ."""
for j in range(n):
for k in range(j):
circ.cp(math.pi/float(2**(j-k)), j, k)
circ.cp(math.pi / float(2 ** (j - k)), j, k)
circ.h(j)


Expand Down Expand Up @@ -74,8 +74,8 @@ def qft(circ, n):

# Second version: real device
least_busy_device = least_busy(
provider.backends(simulator=False,
filters=lambda x: x.configuration().n_qubits > 4))
provider.backends(simulator=False, filters=lambda x: x.configuration().n_qubits > 4)
)
print("Running on current least busy device: ", least_busy_device)
job = execute([qft3, qft4, qft5], least_busy_device, shots=1024)
result = job.result()
Expand Down
8 changes: 4 additions & 4 deletions examples/python/ibmq/using_qiskit_terra_level_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,19 @@
qc1 = QuantumCircuit(2, 2)
qc1.h(0)
qc1.cx(0, 1)
qc1.measure([0,1], [0,1])
qc1.measure([0, 1], [0, 1])

# making another circuit: superpositions
qc2 = QuantumCircuit(2, 2)
qc2.h([0,1])
qc2.measure([0,1], [0,1])
qc2.h([0, 1])
qc2.measure([0, 1], [0, 1])

# setting up the backend
print("(BasicAER Backends)")
print(BasicAer.backends())

# running the job
job_sim = execute([qc1, qc2], BasicAer.get_backend('qasm_simulator'))
job_sim = execute([qc1, qc2], BasicAer.get_backend("qasm_simulator"))
sim_result = job_sim.result()

# Show the results
Expand Down
10 changes: 5 additions & 5 deletions examples/python/ibmq/using_qiskit_terra_level_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@
qc1 = QuantumCircuit(2, 2, name="bell")
qc1.h(0)
qc1.cx(0, 1)
qc1.measure([0,1], [0,1])
qc1.measure([0, 1], [0, 1])

# Making another circuit: superpositions
qc2 = QuantumCircuit(2, 2, name="superposition")
qc2.h([0,1])
qc2.measure([0,1], [0,1])
qc2.h([0, 1])
qc2.measure([0, 1], [0, 1])

# Setting up the backend
print("(Aer Backends)")
for backend in BasicAer.backends():
print(backend.status())
qasm_simulator = BasicAer.get_backend('qasm_simulator')
qasm_simulator = BasicAer.get_backend("qasm_simulator")


# Compile and run the circuit on a real device backend
Expand Down Expand Up @@ -87,7 +87,7 @@
sim_job = qasm_simulator.run(qobj)

# Getting the result
sim_result=sim_job.result()
sim_result = sim_job.result()

# Show the results
print(sim_result.get_counts(qc1))
Expand Down
4 changes: 2 additions & 2 deletions examples/python/ibmq/using_qiskit_terra_level_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
print("(Aer Backends)")
for backend in BasicAer.backends():
print(backend.status())
qasm_simulator = BasicAer.get_backend('qasm_simulator')
qasm_simulator = BasicAer.get_backend("qasm_simulator")


# Compile and run the circuit on a real device backend
Expand Down Expand Up @@ -97,7 +97,7 @@
pm.append(CXDirection(coupling_map))

# unroll to single qubit gates
pm.append(Unroller(['u1', 'u2', 'u3', 'id', 'cx']))
pm.append(Unroller(["u1", "u2", "u3", "id", "cx"]))
qc1_new = pm.run(qc1)
qc2_new = pm.run(qc2)

Expand Down
13 changes: 6 additions & 7 deletions examples/python/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
0,
0,
1 / math.sqrt(4) * complex(1, 0),
1 / math.sqrt(8) * complex(1, 0)]
1 / math.sqrt(8) * complex(1, 0),
]

circuit.initialize(desired_vector, [0, 1, 2, 3])

Expand All @@ -54,17 +55,15 @@

# Desired vector
print("Desired probabilities: ")
print(str(list(map(lambda x: format(abs(x * x), '.3f'), desired_vector))))
print(str(list(map(lambda x: format(abs(x * x), ".3f"), desired_vector))))

# Initialize on local simulator
sim_backend = BasicAer.get_backend('qasm_simulator')
sim_backend = BasicAer.get_backend("qasm_simulator")
job = execute(circuit, sim_backend, shots=shots)
result = job.result()

counts = result.get_counts(circuit)

qubit_strings = [format(i, '0%sb' % 4) for
i in range(2 ** 4)]
qubit_strings = [format(i, "0%sb" % 4) for i in range(2 ** 4)]
print("Probabilities from simulator: ")
print([format(counts.get(s, 0) / shots, '.3f') for
s in qubit_strings])
print([format(counts.get(s, 0) / shots, ".3f") for s in qubit_strings])
Loading

0 comments on commit 9e9ad8a

Please sign in to comment.