I find the current anti-AI/SI sentiment pretty wild. Having watched this space for the last three years, I’ve been more impressed by the sheer velocity of capability growth than anything else.
Of course, we have to be realistic about the trade-offs. There are some big physical hurdles like keeping data center noise in check and making sure our thirst for compute doesn’t destabilize electricity prices. Beyond the hardware, there’s also the persistent, evolving shadow of cybersecurity; as these models become more capable, the risks and complexities of securing our systems remain a constant, high-stakes moving target.
Looking forward, I’m fascinated by the “human-in-the-loop” aspect of this evolution. The real question is: how do we use this to actually accelerate human development? In 20 years, I’d love to see a parabolic ascent in human knowledge, especially in fields like Health, Mathematics, and Physics.
In the world of software engineering, I think “quality” is going to be our biggest hurdle. I see us moving toward a reality where we’re all essentially “bot team leads” and quality reviewers. While a senior engineer with a large model is incredibly productive, we still have to be the ones who can fix the mistakes and triage the mess.
My real concern, though, is for the profession’s pipeline. If AI handles all the “junior” tasks, how do we train the next generation of seniors? We have to figure out how to keep building deep expertise even as the entry-level “grunt work” disappears.
I’m genuinely excited to see what’s next. With major milestones like Navier-Stokes, the Riemann Hypothesis, and the proof that VP != VNP now in the rearview mirror, I find myself wondering: what’s the next big unproved theory waiting to be cracked?
As of this writing I moved on from my previous host and I am now moving to this more modern and secure location. My previous host has been getting more and more expensive and less and less modern featured for years.
It has been quite a while since I last wrote about anything. It has been hard finding a topic that motivated me enough to write about.
Python 2 EoL
Python 2 has had a long run, longer than it should have. On January 1, 2020, Python 2 reached EoL after almost 20 years of support. Version 2 was originally released in October 2000. I started using it around that time. The first python book I bought was written for version 2.1. When Python 3 was first released in December of 2008, it didn’t go so well. Part of Python’s power is the large number of community packages, however this also proved to slow the adaptation of Python 3 as backwards compatibility was broken. Python 3.5, released in September 2015, was the first time that 3.x shined and about that time the number of packages supporting Python 3 vs Python 2 started to shift. Recently, most popular packages have finally dropped all support for Python 2. I hope you have transitioned to version 3.
More than a destination
Programming is more than a destination. Care about the code you right. Just because code works today doesn’t mean it always will. Complex, bad, or hard-to-understand implementations are a permanent cost.
YAGNI
YAGNI – Your not going to need it. Related to the previous section, adding complexity because you think you will need something is not good. Adding complexity means that you have made change more time consuming, more code to review, understand, change, and test.
Installing pyaudio on macOS is almost straightforward, except that you need portaudio installed. The easiest way to remedy this is to use homebrew. If you have your homebrew installing in the recomended location it is as simple as the following:
brew install portaudio
pipenv install pyaudio
However if you have homebrew using a non-standard location, it requires a few additional settings, if you don’t have them set already.
Sometimes you find yourself needing to work at the byte-level in an application you are working on. I feel that in Python there are not enough examples of how to do this. There is also a lot of potential to over-complicate the solution.
This Example
I plan to cover several aspects of working with bytes in this example. I’ll cover working with the struct package, the bytearray built-in and the ctypes module.
The Code
from ctypes import c_int, Structure
from struct import pack_into, unpack_from
# create 2 buffers, one smaller than the other for
# demonstration purposes.
buff1 = bytearray(64)
buff2 = bytearray(32)
# first we'll use the struct package to initalize the arrays.
# initialize buff1 with 32 integers.
pack_into('I' * 16, buff1, 0, *range(0, 16))
print('Buffer 1:', unpack_from('I' * 16, buff1, 0))
# for the sake of demonstration, we'll work with buff2.
# copy part of buff1 into buff2, since we're using
# bytearrays, this should be equivalent to a memcpy
buff2[:] = buff1[:32]
# test it out, did we copy 32 bytes from buff1 into buff2?
print('Buffer 2:', unpack_from('I' * 8, buff2, 0), end='\n\n')
# We can also use the ctypes package to access the buffers
# We can access it piece-meal like this. Note that this
# copies the buffer, if we didn't want a copy. from_buffer
# is the function we would use.
x = c_int.from_buffer_copy(buff2, 8)
y = c_int.from_buffer_copy(buff2, 12)
print(f'x, y as 2 standalone c_ints: {x.value}, {y.value}', end='\n\n')
# You can also create C Structures to access the data
# Define a simple ctypes structure.
class Point(Structure):
_fields_ = [
('x', c_int),
('y', c_int)
]
p1 = Point.from_buffer_copy(buff2, 8)
print(f'x, y as elements of a ctype structure (copied): {p1.x}, {p1.y}')
# note that since this is a copy any manipulation doesn't
# effect the buffer.
p1.x, p1.y = 50, 51
print(f'p1.x, p1.y set to: {p1.x}, {p1.y}')
print('Show buff2 is unchanged:', unpack_from('I' * 8, buff2, 0), end='\n\n')
# so, if we wanted to directly manipulate the buffer using the structure
p2 = Point.from_buffer(buff2, 8)
print(f'x, y as elements of a ctype structure (not copied): {p1.x}, {p1.y}')
p2.x, p2.y = 100, 101
print(f'p2.x, p2.y set to: {p2.x}, {p2.y}')
# see that the 3rd and 4th element now been changed.
print('Show buff2 is changed:', unpack_from('I' * 8, buff2, 0), end='\n\n')
# finally note that the original buffer is unchanged.
print('Show buff1 unchanged:', unpack_from('I' * 16, buff1, 0))
Output
Buffer 1: (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)
Buffer 2: (0, 1, 2, 3, 4, 5, 6, 7)
x, y as 2 standalone c_ints: 2, 3
x, y as elements of a ctype structure (copied): 2, 3
p1.x, p1.y set to: 50, 51
Show buff2 is unchanged: (0, 1, 2, 3, 4, 5, 6, 7)
x, y as elements of a ctype structure (not copied): 50, 51
p2.x, p2.y set to: 100, 101
Show buff2 is changed: (0, 1, 100, 101, 4, 5, 6, 7)
Show buff1 unchanged: (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)
A statement on copying
Be careful with slicing a python bytearray, bytes or array.array. Slicing creates a copy and can impact the performance of your application. There is a better way; enter memoryview. Memoryview works with anything that implements the Python Buffer Protocol and makes slicing very efficient. Slicing a memoryview will result in another memoryview, not a copy of the bytes represented.
I was using Python to encode a CSV file using a custom dialect recently when I noticed something odd. I noticed that the csv writer class takes an optional argument that enables you to change the line terminator. That’s ok, however, the csv reader class does not honor the argument. So, through the default api, you can create CSV that you cannot read back in with the default api. According to the documentation, this applies to Python 2.7 through 3.7. It also probably applies to versions < 2.7 but that documentation is no longer online. Python.org Documentation
A Simple Script
I wrote the following simple script to illustrate this oddity. Basically it has a list of lists that it converts to CSV and back using various line terminators, if the output differs from the source, the difference is displayed.
import csv
import io
import re
def convert_to_csv_and_back(rows: list, lineterminator: str):
with io.StringIO() as o:
writer = csv.writer(o, lineterminator=lineterminator)
for row in rows:
writer.writerow(row)
with io.StringIO(o.getvalue()) as i:
reader = csv.reader(i, lineterminator=lineterminator)
return list(reader)
source = [
['this', 'is', 'row', '1'],
['this', 'is', 'row', '2'],
['this', 'is', 'row', '3']
]
lineterminators = ['|', ':', '\t', '\r\n']
for terminator in lineterminators:
output = convert_to_csv_and_back(source, terminator)
source_set = set(map(tuple, source))
output_set = set(map(tuple, output))
difference = source_set.symmetric_difference(output_set)
to_from_csv_failed = len(difference)
print(f'Line Terminator: {repr(terminator)}')
print(f'To/From CSV Worked: {"No" if to_from_csv_failed else "Yes"}')
print(f'Source: {source}')
print(f'Output: {output}')
if to_from_csv_failed:
print(f'Difference: {difference}')
print('--------------------------')
Results
As you can see from the results here; with the exception of ‘\r\n’, all the various line terminators failed.
So, why would you want to specify the line terminators with the CSV module? There are probably only a handful of reasons, my only reason would be a custom dialect where I wanted to ensure that there were no carriage returns or line feeds in. 99.9% of the time, you want ‘\r\n’.
The August 21, 2017 Solar Eclipse as photographed from Sparta, TN (35.9727° N, 85.5638° W). This was about 3.2 miles from the center of Totality! These images do not convey the magnitude of the experience. Knowing what to expect in general does not prepare you. If I tried to find a single word to describe it, I would pick astonishing.
Chad Dotson – 2017 Solar Eclipse –
Sparta, Tennessee (35.9727° N, 85.5638° W) –
2m38.8s of Totality
Chad Dotson – 2017 Solar Eclipse –
Sparta, Tennessee (35.9727° N, 85.5638° W) –
2m38.8s of Totality
Awhile back I had some thoughts on communication. If you’ve ever played World of Tanks Blitz you’d know that basically its a team of tanks against another team of tanks. With the pick up, fast paced nature communication is minimal at best (sometimes limited to a single “<<<<<<<<<” or “>>>>>>>>>” indicating which direction to take the offense). I found that teams that could coordinate with minimal communication, play their tank roles (scouts, mediums, heavies, and destroyers), and move fast could achieve massive overwhelming victories. Something similar is probably true in an agile/teamwork environment. Know your stuff, know your role, take opportunities, work together, succeed.
Have you ran into trouble with SSLErrors after upgrading to Python 3.6 on macOS Sierra? For me, my first encounter was downloading the bokeh sample data (included here).
Python 3.6.0 (v3.6.0:41df79263a11, Dec 22 2016, 17:23:13)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import bokeh.sampledata
>>> bokeh.sampledata.download()
Using data directory: /Users/chad/.bokeh/data
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1318, in do_open
encode_chunked=req.has_header('Transfer-encoding'))
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1285, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1234, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1026, in _send_output
self.send(msg)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 964, in send
self.connect()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1400, in connect
server_hostname=server_hostname)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 401, in wrap_socket
_context=self, _session=session)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 808, in __init__
self.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 1061, in do_handshake
self._sslobj.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 683, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/chad/Library/Python/3.6/lib/python/site-packages/bokeh/sampledata/__init__.py", line 81, in download
_getfile(base_url, file_name, data_dir, progress=progress)
File "/Users/chad/Library/Python/3.6/lib/python/site-packages/bokeh/sampledata/__init__.py", line 87, in _getfile
url = urlopen(file_url)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 223, in urlopen
return opener.open(url, data, timeout)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 526, in open
response = self._open(req, data)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 544, in _open
'_open', req)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 504, in _call_chain
result = func(*args)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1361, in https_open
context=self._context, check_hostname=self._check_hostname)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1320, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)>
I finally got a chance to research exactly what was wrong. Given that Python 3.5 was working on my machine and 3.6 was working on several linux machines, I thought that it could have been an issue with Python 3.6, unlikely as it may be. After no bug fix version was released I realized that it must be my configuration.
Searching, I found one result related to this in the Python issue tracker: Issue 28150. One answerer points out that Python on macOS no longer relies on Apple’s version of OpenSSL, instead it is shipped with a new one. The gotcha: this new one does not have trust certificates installed. All this is detailed in the Readme.
The Installer Readme
So, as the Python issue tracker mentioned, there is an entry in the installer readme. Perhaps I should read these closer…
Certificate verification and OpenSSL
**NEW** This variant of Python 3.6 now includes its own private copy of OpenSSL 1.0.2. Unlike previous releases, the deprecated Apple-supplied OpenSSL libraries are no longer used. This also means that the trust certificates in system and user keychains managed by the Keychain Access application and the security command line utility are no longer used as defaults by the Python ssl module. For 3.6.0, a sample command script is included in /Applications/Python 3.6 to install a curated bundle of default root certificates from the third-party certifi package (https://pypi.python.org/pypi/certifi). If you choose to use certifi, you should consider subscribing to the project’s email update service to be notified when the certificate bundle is updated.
The bundled pip included with the Python 3.6 installer has its own default certificate store for verifying download connections.
Run the download script provided with the installer – /Applications/Python 3.6/Install Certificates.command.
For myself, I ran the bundled script and everything seems to be functioning fine. It seems more than a little odd that this was not done on installation.