Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Lint and Format

on:
push:
branches:
- master
- 'release/*'
pull_request:
branches:
- master
workflow_dispatch:

env:
CLICOLOR: 1

jobs:
ruff:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v5

- name: Ruff format check
uses: astral-sh/ruff-action@v3
with:
args: "format --check"

- name: Ruff lint
uses: astral-sh/ruff-action@v3
with:
args: "check"
File renamed without changes.
14 changes: 14 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
target-version = "py312"
line-length = 79
exclude = ["deps"]
extend-include = ["*.drs"]

[lint]
ignore = ["E741"]

[format]
docstring-code-format = true

[lint.per-file-ignores]
"*.ipynb" = ["F403", "F405"]
"*.drs" = ["F403", "F405", "F821"]
80 changes: 45 additions & 35 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,38 +31,40 @@
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['sphinx.ext.autodoc',
'sphinx.ext.doctest',
'sphinx.ext.mathjax',
'sphinx.ext.viewcode',
'sphinx.ext.napoleon',
'sphinx.ext.imgconverter',
'sphinx.ext.githubpages'
]
extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.doctest",
"sphinx.ext.mathjax",
"sphinx.ext.viewcode",
"sphinx.ext.napoleon",
"sphinx.ext.imgconverter",
"sphinx.ext.githubpages",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
source_suffix = ".rst"

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# General information about the project.
project = 'drudge'
copyright = '2017, Jinmo Zhao and Gustavo E Scuseria'
author = 'Jinmo Zhao and Gustavo E Scuseria'
project = "drudge"
copyright = "2017, Jinmo Zhao and Gustavo E Scuseria"
author = "Jinmo Zhao and Gustavo E Scuseria"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
from drudge import __version__
from drudge import __version__ # noqa: E402

version = __version__
# The full version, including alpha/beta/rc tags.
release = __version__
Expand All @@ -77,10 +79,10 @@
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

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

# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False
Expand All @@ -91,7 +93,7 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'
html_theme = "alabaster"

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
Expand All @@ -102,13 +104,13 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]


# -- Options for HTMLHelp output ------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'drudgedoc'
htmlhelp_basename = "drudgedoc"


# -- Options for LaTeX output ---------------------------------------------
Expand All @@ -117,15 +119,15 @@
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

#
# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

#
# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

#
# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
Expand All @@ -135,19 +137,21 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'drudge.tex', 'drudge Documentation',
'Jinmo Zhao and Gustavo E Scuseria', 'manual'),
(
master_doc,
"drudge.tex",
"drudge Documentation",
"Jinmo Zhao and Gustavo E Scuseria",
"manual",
),
]


# -- Options for manual page output ---------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'drudge', 'drudge Documentation',
[author], 1)
]
man_pages = [(master_doc, "drudge", "drudge Documentation", [author], 1)]


# -- Options for Texinfo output -------------------------------------------
Expand All @@ -156,19 +160,25 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'drudge', 'drudge Documentation',
author, 'drudge', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
"drudge",
"drudge Documentation",
author,
"drudge",
"One line description of project.",
"Miscellaneous",
),
]


autodoc_member_order = 'bysource'
autodoc_member_order = "bysource"

doctest_global_setup = '''
doctest_global_setup = """
import os

from dummy_spark import SparkContext

from sympy import *
from drudge import *
'''
"""
21 changes: 7 additions & 14 deletions docs/examples/ccd.drs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
set_dbbar_base(t, 2)

# Einstein summation convention can be used for easy tensor creation.
t2 = einst(
t[a, b, i, j] * c_dag[a] * c_dag[b] * c_[j] * c_[i] / 4
)
t2 = einst(t[a, b, i, j] * c_dag[a] * c_dag[b] * c_[j] * c_[i] / 4)

# Get the similarity-transformed Hamiltonian. Note that ``|`` operator
# computes the commutator between operators.
Expand All @@ -21,22 +19,17 @@ c1 = simplify(c0 | t2)
c2 = simplify(c1 | t2)
c3 = simplify(c2 | t2)
c4 = simplify(c3 | t2)
h_bar = simplify(
c0 + c1 + (1/2) * c2 + (1/6) * c3 + (1/24) * c4
)
h_bar = simplify(c0 + c1 + (1 / 2) * c2 + (1 / 6) * c3 + (1 / 24) * c4)

print('Similarity-transformed Hamiltonian has {} terms'.format(
n_terms(h_bar)
))
print("Similarity-transformed Hamiltonian has {} terms".format(n_terms(h_bar)))

# Derive the working equations by projection.
en_eqn = simplify(eval_fermi_vev(h_bar))
proj = c_dag[i] * c_dag[j] * c_[b] * c_[a]
t2_eqn = simplify(eval_fermi_vev(proj * h_bar))

print('Working equation derived!')

with report('ccd.html', 'CCD theory') as rep:
rep.add('Energy equation', en_eqn)
rep.add('Doubles amplitude equation', t2_eqn)
print("Working equation derived!")

with report("ccd.html", "CCD theory") as rep:
rep.add("Energy equation", en_eqn)
rep.add("Doubles amplitude equation", t2_eqn)
29 changes: 13 additions & 16 deletions docs/examples/ccd_adv.drs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
#

set_dbbar_base(t, 2)
t2 = einst(
t[a, b, i, j] * c_dag[a] * c_dag[b] * c_[j] * c_[i] / 4
)
t2 = einst(t[a, b, i, j] * c_dag[a] * c_dag[b] * c_[j] * c_[i] / 4)


def compute_h_bar():
"""Compute the similarity transformed Hamiltonian."""
Expand All @@ -21,11 +20,12 @@ def compute_h_bar():
h_bar += curr
return simplify(h_bar)


# By using the `memoise` function, the result can be automatically dumped into
# the given pickle file, and read from it if it is already available. This can
# be convenient for large multi-step jobs.
h_bar = memoize(compute_h_bar, 'h_bar.pickle')
print('H-bar has {} terms'.format(n_terms(h_bar)))
h_bar = memoize(compute_h_bar, "h_bar.pickle")
print("H-bar has {} terms".format(n_terms(h_bar)))

# Derive the working equations by projection. Here we make them into tensor
# definition with explicit left-hand side, so that they can be used for
Expand All @@ -34,13 +34,11 @@ e <<= simplify(eval_fermi_vev(h_bar))
proj = c_dag[i] * c_dag[j] * c_[b] * c_[a]
r2[a, b, i, j] <<= simplify(eval_fermi_vev(proj * h_bar))

print('Working equation derived!')
print("Working equation derived!")

# When the gristmill package is also installed, the evaluation of the working
# equations can also be optimized with it.
eval_seq = optimize(
[e, r2], substs={no: 1000, nv: 10000}
)
eval_seq = optimize([e, r2], substs={no: 1000, nv: 10000})

# In addition to HTML report, we can also have LaTeX report. Note that the
# report can be structured into sections with descriptions. For LaTeX output,
Expand All @@ -53,11 +51,10 @@ The optimization is based on 1000 occupied orbitals and 10000 virtual orbitals,
which should be representative of common problems for CCD theory.
"""

with report('ccd.tex', 'CCD theory') as rep:
rep.add(title='Working equations')
rep.add(content=e, description='The energy equation')
rep.add(content=r2, description='Doubles amplitude equation', env='dmath')
rep.add(title='Optimized evaluation', description=opt_description)
with report("ccd.tex", "CCD theory") as rep:
rep.add(title="Working equations")
rep.add(content=e, description="The energy equation")
rep.add(content=r2, description="Doubles amplitude equation", env="dmath")
rep.add(title="Optimized evaluation", description=opt_description)
for step in eval_seq:
rep.add(content=step, env='dmath')

rep.add(content=step, env="dmath")
28 changes: 13 additions & 15 deletions docs/examples/ccsd.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"outputs": [],
"source": [
"from pyspark import SparkContext\n",
"ctx = SparkContext('local[*]', 'ccsd')"
"\n",
"ctx = SparkContext(\"local[*]\", \"ccsd\")"
]
},
{
Expand All @@ -49,6 +50,7 @@
"outputs": [],
"source": [
"from dummy_spark import SparkContext\n",
"\n",
"ctx = SparkContext()"
]
},
Expand Down Expand Up @@ -99,11 +101,11 @@
},
"outputs": [],
"source": [
"t = IndexedBase('t')\n",
"t = IndexedBase(\"t\")\n",
"\n",
"clusters = dr.einst(\n",
" t[a, i] * c_dag[a] * c_[i] +\n",
" t[a, b, i, j] * c_dag[a] * c_dag[b] * c_[j] * c_[i] / 4\n",
" t[a, i] * c_dag[a] * c_[i]\n",
" + t[a, b, i, j] * c_dag[a] * c_dag[b] * c_[j] * c_[i] / 4\n",
")"
]
},
Expand Down Expand Up @@ -165,12 +167,7 @@
}
],
"source": [
"dr.set_symm(\n",
" t,\n",
" Perm([1, 0, 2, 3], NEG),\n",
" Perm([0, 1, 3, 2], NEG),\n",
" valence=4\n",
")"
"dr.set_symm(t, Perm([1, 0, 2, 3], NEG), Perm([0, 1, 3, 2], NEG), valence=4)"
]
},
{
Expand Down Expand Up @@ -444,9 +441,9 @@
")\n",
"\n",
"working_eqn = [\n",
" dr.define(Symbol('e'), en_eqn), \n",
" dr.define(r1[a, i], t1_eqn), \n",
" dr.define(r2[a, b, i, j], t2_eqn)\n",
" dr.define(Symbol(\"e\"), en_eqn),\n",
" dr.define(r1[a, i], t1_eqn),\n",
" dr.define(r2[a, b, i, j], t2_eqn),\n",
"]"
]
},
Expand Down Expand Up @@ -511,8 +508,9 @@
"%%time\n",
"\n",
"eval_seq = optimize(\n",
" working_eqn, substs={p.nv: 5000, p.no: 1000}, \n",
" contr_strat=ContrStrat.EXHAUST\n",
" working_eqn,\n",
" substs={p.nv: 5000, p.no: 1000},\n",
" contr_strat=ContrStrat.EXHAUST,\n",
")"
]
},
Expand Down
3 changes: 1 addition & 2 deletions docs/examples/conf_ph_spin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Configuration for particle-hole problem with explicit spin.
"""
"""Configuration for particle-hole problem with explicit spin."""

from pyspark import SparkContext
from drudge import RestrictedPartHoleDrudge
Expand Down
Loading
Loading