This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import UserDict | |
from collections.abc import Mapping | |
from typing import Optional | |
############################################################################### | |
class FallbackDict(UserDict): | |
"""A dict-like which falls back on another mapping for missing keys |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Provided by poppler, which can be installed through macports | |
## From https://apple.stackexchange.com/a/445704 | |
pdfimages -all input.pdf output |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Convert text in any installed font to the WKT format. | |
Requires inkscape. | |
Does not currently work for characters with disjoint top-level islands (eg "=", | |
double quotes, capital Xi, etc.) | |
''' | |
import json |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Specify the env will be emulating x86 | |
CONDA_SUBDIR=osx-64 conda create -n <env_name> python=3.10 | |
# Activate env | |
conda activate <env_name> | |
# Set env to fetch x86 packages | |
conda config --env --set subdir osx-64 | |
# Install qiskit metal | |
pip install qiskit-metal | |
# Install just the notebook component of jupyter | |
# Don't install the full 'jupyter' package which will lead to qt conflicts |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import msgpack | |
import msgpack_numpy | |
import pandas as pd | |
import qutip | |
from scipy.sparse import csr_matrix | |
def serialize_csr(arr): | |
## Switch to coo format | |
coo = arr.tocoo() | |
## Separate into the components we need to reconstruct it |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## From https://github.com/qutip/qutip/issues/1571#issuecomment-859873615 | |
times = [0, ...] | |
# Liouvillians for parts you have control over | |
control_liouvillians = [qutip.liouvillian(h) for h in control_hamiltonians] | |
# The time-dependent Hamiltonian for stuff you're not controlling | |
base_hamiltonian = qutip.QobjEvo([H0, [H1, time_dependence], ...]) | |
# Turn it into a Liouvillian once, so we don't repeat the cost | |
base = qutip.liouvillian(base_hamiltonian, collapse_operators) | |
state = ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Write metadata to pdf files with no warnings. | |
Useful for provenance, and in this way we can suppress warnings for end users of a larger application | |
""" | |
from matplotlib.backends.backend_pdf import PdfPages | |
import matplotlib.pyplot as plt | |
import numpy as np | |
import warnings |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
import logging | |
import os | |
import sys | |
def quick_config(logger, | |
console_log_level=logging.INFO, file_log_level=logging.DEBUG, | |
console_fmt='[%(asctime)s] %(message)s', | |
console_datefmt='%y-%m-%d %H:%M:%S', | |
log_file_name=None, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
def check_appearance(): | |
"""Checks DARK (True)/LIGHT(False) mode of macos. | |
https://stackoverflow.com/a/65357166""" | |
cmd = 'defaults read -g AppleInterfaceStyle' | |
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, | |
stderr=subprocess.PIPE, shell=True) | |
return bool(p.communicate()[0]) |
NewerOlder