diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c9616d514..0e285ced5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -270,6 +270,17 @@ out$> make style out$> make mypy ``` +If you edit any documentation, refer to [IBM Quantum's writing style +guide](https://github.com/IBM/ibm-quantum-style-guide). You can use +[Vale](https://vale.sh) to automatically check some of these rules for you. +With Vale installed, run the following command + +```sh +make docs-test +``` + +To add a word to the dictionary, add it to `test/docs/dictionary.txt`. + ### Development Cycle The development cycle for qiskit-ibm is all handled in the open using diff --git a/Makefile b/Makefile index 1d9099ef5..3cd601802 100644 --- a/Makefile +++ b/Makefile @@ -32,6 +32,9 @@ integration-test: e2e-test: python -m unittest discover --verbose --top-level-directory . --start-directory test/e2e +docs-test: + ./test/docs/vale.sh + unit-test-coverage: coverage run -m unittest discover --verbose --top-level-directory . --start-directory test/unit coverage lcov diff --git a/docs/.vale.ini b/docs/.vale.ini new file mode 100644 index 000000000..13557c9fc --- /dev/null +++ b/docs/.vale.ini @@ -0,0 +1,12 @@ +StylesPath = ../test/docs +MinAlertLevel = suggestion + +[[!_]**.{md,rst}] +BasedOnStyles = IBMQuantum + +[apidocs/ibm-runtime.rst] +IBMQuantum.Headings = NO + +# skip './stubs' +[stubs/**] +BasedOnStyles = '' diff --git a/requirements-dev.txt b/requirements-dev.txt index 63322ebcd..6113ed906 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -7,6 +7,7 @@ sphinx-rtd-theme>=0.4.0 sphinx-tabs>=1.1.11 sphinx-automodapi sphinx-autodoc-typehints<=1.19.2 +nbqa==1.5.3 matplotlib>=2.1 jupyter jupyter-sphinx diff --git a/test/docs/IBMQuantum/Abbreviations.yml b/test/docs/IBMQuantum/Abbreviations.yml new file mode 100644 index 000000000..e7b85f235 --- /dev/null +++ b/test/docs/IBMQuantum/Abbreviations.yml @@ -0,0 +1,7 @@ +extends: existence +message: "Do not use periods in all-uppercase abbreviations such as '%s'." +link: 'https://www.ibm.com/developerworks/library/styleguidelines/index.html#N100DC' +level: error +nonword: true +tokens: + - '\b(?:[A-Z]\.){3,5}' diff --git a/test/docs/IBMQuantum/DashSpacing.yml b/test/docs/IBMQuantum/DashSpacing.yml new file mode 100644 index 000000000..ea9a103b7 --- /dev/null +++ b/test/docs/IBMQuantum/DashSpacing.yml @@ -0,0 +1,13 @@ +extends: existence +message: "Add spaces around the dash in '%s'." +link: 'https://www.ibm.com/developerworks/library/styleguidelines/index.html#N106BF' +ignorecase: true +nonword: true +level: error +action: + name: edit + params: + - remove + - ' ' +tokens: + - '[^\s][—–][^\s]' diff --git a/test/docs/IBMQuantum/Definitions.yml b/test/docs/IBMQuantum/Definitions.yml new file mode 100644 index 000000000..b60b88851 --- /dev/null +++ b/test/docs/IBMQuantum/Definitions.yml @@ -0,0 +1,69 @@ +extends: conditional +message: "Define acronyms and abbreviations (such as '%s') on first occurrence if they're likely to be unfamiliar." +link: 'https://www.ibm.com/developerworks/library/styleguidelines/index.html#N100DC' +level: suggestion +ignorecase: false +# Ensures that the existence of 'first' implies the existence of 'second'. +first: '\b([A-Z]{3,5}s?)\b' +second: '\(([A-Z]{3,5}s?)\)' +# ... with the exception of these: +exceptions: + - API + - ASP + - CLI + - CPU + - CNOT + - CSS + - CSV + - DEBUG + - DOM + - DPI + - FAQ + - GCC + - GDB + - GET + - GPU + - GTK + - GUI + - HTML + - HTTP + - HTTPS + - IBM + - IDE + - JAR + - JSON + - JSX + - LESS + - LLDB + - NBQA + - NET + - NOTE + - NVDA + - OSS + - PATH + - PDF + - PHP + - POST + - QPU + - RAM + - REPL + - RSA + - SCM + - SCSS + - SDK + - SQL + - SSH + - SSL + - SVG + - SWAT + - TBD + - TCP + - TODO + - URI + - URL + - USB + - UTF + - XML + - XSS + - YAML + - ZIP diff --git a/test/docs/IBMQuantum/Headings.yml b/test/docs/IBMQuantum/Headings.yml new file mode 100644 index 000000000..cd0f4f770 --- /dev/null +++ b/test/docs/IBMQuantum/Headings.yml @@ -0,0 +1,28 @@ +extends: capitalization +message: "'%s' should use sentence-style capitalization." +link: 'https://www.ibm.com/developerworks/library/styleguidelines/index.html#N1030C' +level: warning +scope: heading +match: $sentence +indicators: + - ':' + - '.' + - ')' +exceptions: + - API + - App ID + - IBM + - IBM Quantum + - Qiskit + - Runtime + - Sampler + - Estimator + - Terraform + - Trotter + - Grover + - Hamiltonian + - Hamiltonians + - Cloud + - Spectroscopic Eigensolver Algorithm + - Variational Quantum Eigensolver + - (\d+)\. diff --git a/test/docs/IBMQuantum/However.yml b/test/docs/IBMQuantum/However.yml new file mode 100644 index 000000000..e1322dc45 --- /dev/null +++ b/test/docs/IBMQuantum/However.yml @@ -0,0 +1,7 @@ +extends: existence +message: Double-check your punctuation around 'however' (see github.com/IBM/ibm-quantum-style-guide/issues/10 for more information). +level: suggestion +code: false +ignorecase: false +raw: + - ([^;,] however|however[^,]) diff --git a/test/docs/IBMQuantum/Latin.yml b/test/docs/IBMQuantum/Latin.yml new file mode 100644 index 000000000..b0d2b2b1c --- /dev/null +++ b/test/docs/IBMQuantum/Latin.yml @@ -0,0 +1,13 @@ +extends: substitution +message: "Use '%s' instead of '%s'." +link: 'https://www.ibm.com/developerworks/library/styleguidelines/index.html#wordlist' +ignorecase: true +level: error +nonword: true +action: + name: replace +swap: + '\b(?:eg|e\.g\.)[\s,]': for example + '\b(?:ie|i\.e\.)[\s,]': that is + '\betc\.': and so on + '\bvs\.': versus diff --git a/test/docs/IBMQuantum/OxfordComma.yml b/test/docs/IBMQuantum/OxfordComma.yml new file mode 100644 index 000000000..6e7f76c7a --- /dev/null +++ b/test/docs/IBMQuantum/OxfordComma.yml @@ -0,0 +1,6 @@ +extends: existence +message: "Use the Oxford comma in '%s'." +link: 'https://www.ibm.com/developerworks/library/styleguidelines/index.html#N106BF' +level: suggestion +tokens: + - '(?:[^,]+,){1,}\s\w+\sand' diff --git a/test/docs/IBMQuantum/Politeness.yml b/test/docs/IBMQuantum/Politeness.yml new file mode 100644 index 000000000..43bf6975d --- /dev/null +++ b/test/docs/IBMQuantum/Politeness.yml @@ -0,0 +1,9 @@ +extends: existence +message: "Don't use '%s'" +link: 'https://github.com/IBM/ibm-quantum-style-guide/issues/16' +ignorecase: true +level: error +tokens: + - please + - thanks + - thank you diff --git a/test/docs/IBMQuantum/Repetition.yml b/test/docs/IBMQuantum/Repetition.yml new file mode 100644 index 000000000..102ebb3ce --- /dev/null +++ b/test/docs/IBMQuantum/Repetition.yml @@ -0,0 +1,6 @@ +extends: repetition +message: "'%s' is repeated!" +level: error +alpha: true +tokens: + - '[^\s]+' diff --git a/test/docs/IBMQuantum/Spelling.yml b/test/docs/IBMQuantum/Spelling.yml new file mode 100644 index 000000000..1dc1ad07a --- /dev/null +++ b/test/docs/IBMQuantum/Spelling.yml @@ -0,0 +1,5 @@ +extends: spelling +message: "Unknown word '%s'; fix or add to dictionary." +level: error +ignore: + - dictionary.txt diff --git a/test/docs/IBMQuantum/Terms.yml b/test/docs/IBMQuantum/Terms.yml new file mode 100644 index 000000000..77527dfeb --- /dev/null +++ b/test/docs/IBMQuantum/Terms.yml @@ -0,0 +1,184 @@ +extends: substitution +message: Use '%s' rather than '%s' +link: 'https://www.ibm.com/developerworks/library/styleguidelines/index.html#wordlist' +level: warning +ignorecase: true +action: + name: replace +# swap maps tokens in form of bad: good +swap: + '(?:Ctrl|control)-click': press Ctrl and click + 'a lot(?: of)?': many|much + 'backward(?:-)?compatible': compatible with earlier versions + 'down(?:-)?level': earlier|previous|not at the latest level + 'mash(?: )?up': create + 'pop-up (?:blocker|killer)': software to block pop-up ad windows + 're(?:-)?occur': recur + 'sort(?:-|/)?merge': sort|merge + 'do(?: )(?!not|so)': complete|perform + + bottom: end|last + below: following + above: previous + top: start|beginning|first + a number of: several + abort: cancel|stop + administrate: administer + all caps: uppercase + and/or: a or b|a, b, or both + as long as: if|provided that + as per: according to|as|as in + back-level: earlier|previous|not at the latest level + Big Blue: IBM + blink: flash + blue screen of death: stop error + breadcrumbing: breadcrumb trail + canned: preplanned|preconfigured|predefined + case insensitive: not case-sensitive + catastrophic error: unrecoverable error + CBE: Common Base Event + CBTS: CICS BTS|BTS + cold boot: hardware restart + cold start: hardware restart + comes with: includes + componentization: component-based development|component model|component architecture|shared components + componentize: develop components + comprised of: consist of + connect with: connect to + context menu: menu|pop-up menu + contextual help: help|context-sensitive help + crash: fail|lock up|stop|stop responding + CRUD: create retrieve update and delete + customer: client + datum: data + debuggable: debug + deconfigure: unconfigure + deinstall: uninstall + deinstallation: uninstallation + demilitarized zone: DMZ + demo: demonstration + depress: press|type + deregister: unregister + desire: want|required + destroy: delete from the database + dismount: demount|unmount|remove + downgrade: upgrade|fallback|fall back|rollback|roll back + downward compatible: compatible with earlier versions + drag and drop: drag + drill up: navigate + e-fix: fix|interim fix + eFix: fix|interim fix + end user: user + end-user interface: graphical interface|interface + EUI: graphical user interface|interface + expose: display|show|make available + fill in: complete|enter|specify + fixed disk drive: hard disk drive + flavor: version|method + floppy disk: diskette|diskette drive + floppy drive: diskette|diskette drive + floppy: diskette|diskette drive + forward compatible: compatible with later versions + gzip: compress + gzipped: archive|compressed file + hard drive: hard disk|hard disk drive + hard file: hard disk|hard disk drive + hence: therefore + i-fix: interim fix + i-Fix: interim fix + IBM's: IBM's|IBM's AIX + ifix: interim fix + iFix: interim fix + in order to: to + in other words: for example|that is + in spite of: regardless of|despite + in the event: in case|if|when + inactivate: deactivate + information on: information about + information technology: IT + instead of: rather than + insure: ensure + Internet address: IP address|URL|Internet email address|web address + irrecoverable: unrecoverable + jar: compress|archive + keep in mind: remember + launch: start|open + left-hand: left + leverage: use + line cord: power cable|power cord + main directory: root directory + memory stick: USB flash drive + microcomputer: PC + motherboard: system board + mouse over: point to|move the mouse pointer over|Mouse|mouse over + network-centric computing: network computing + non-English: in languages other than English|non-English-language + nonrecoverable: unrecoverable + notion: concept + off-premise: on-premises|off-premises|onsite|offsite + offline storage: auxiliary storage + okay: OK + on ramp: access method + on the fly: dynamically|as needed|in real time|immediately + on the other hand: however|alternatively|conversely + on-premise: on-premises|off-premises|onsite|offsite + on-ramp: access method + pain point: challenge|concern|difficulty|issue + parent task: parent process + patch: fix|test fix|interim fix|fix pack|program temporary fix + perimeter network: DMZ + power down: turn on|turn off + power off: turn on|turn off + power on: turn on|turn off + preload: preinstall|preinstalled + preloaded: preinstall|preinstalled + prepend: add a prefix to + prior to: before + recommend: suggest + retry: retry|try again + right double-click: double right-click + right-hand: right + rule of thumb: rule + sanity check: test|evaluate + secondary storage: auxiliary storage + selection button: left mouse button + serial database: nonpartitioned database environment + shift-click: press Shift and click + ship: include|included + Simple Object Access Protocol: SOAP + single quote mark: single quotation mark + single quote: single quotation mark + SME routine: session management exit routine + start up: start + sunset: withdraw from service|withdraw from marketing|discontinue|no longer support + switch off: power on|turn on|power off|turn off + switch on: power on|turn on|power off|turn off + tar: compress|archive + tarball: tar file + terminate: end|stop + thru: through + thumbstick: USB flash drive + thus: therefore + toggle off: toggle + tooling: tools + touchscreen: touch-sensitive screen + transition: make the transition|move|migrate|change + transparent: indiscernible|not visible + typo: typing error|typographical error + uncheck: clear + uncompress: decompress + undeploy: remove|withdraw + unjar: extract + unselect: clear|deselect + untar: extract + unzip: unzip + upward compatible: compatible with later versions + utilize: use + versus: compared to + via: through + warning notice: attention notice + web-enable: enable for the web + webinar: webinar|webcast|web seminar|web-based event + wish: want + zero out: zero + zip: zip|compress diff --git a/test/docs/dictionary.txt b/test/docs/dictionary.txt new file mode 100644 index 000000000..81c20c11b --- /dev/null +++ b/test/docs/dictionary.txt @@ -0,0 +1,245 @@ +Abelian +Abhinav +Aer +Akira +Amyra +Andersson +Andriyash +Aroosa +Arunachalam +Asfaw +Auditability +Babbush +Barowski +Bello +Bengio +Bergholm +Bernagozzi +Bertels +Bertet +Boeblingen +Boixo +Boulant +Briegel +Broughton +Brukner +Bucher +CNOTs +Carleo +Carrera +Cerezo +Chuang +Cincio +Clauser +Colbeck +Corcoles +Courville +Derks +Deutsch +Deutschle +Dewes +Dunjko +Elies +Esteve +Faehrmann +Farhi +Fock +Francesco +Fredkin +Gacon +Garey +Glick +Goemans +Gogolin +Goodfellow +Greenberger +Griffiths +Gutmann +Hadamard +Haide +Hamiltonian +Hamiltonians +Harkins +Hartmut +Hartree +Havlicek +Hellinger +Hindy +Hiptmair +Hoyer +Hubregtsen +Ijaz +Iten +Izaac +Jakob +Jozsa +Jurcevic +Kandala +Keras +Killoran +Kitaev +Koen +Kohli +Kristan +Kulchytskyy +Kus +Lauro +Leib +Litinski +Liu +Lorenza +Lucchi +Lukasz +Maika +Markus +Masoud +Melko +Mezzacapo +Minev +Mohseni +Mondada +Mosca +Mueggenburg +Neven +Ong +Opflow +Osodo +Ozair +Peruzzo +Petar +Petruccione +Pichlmeier +Plesch +QPUs +Qiskit's +Ravi +Revview +Rivero +Rolfe +Runtime's +Schmitt +Schroeter +Schuld +Schwarz +Shadbolt +Shen +Shende +Shewchuk +Shimony +Shor's +Simulatable +Smelyanskiy +Srinivasan +Stamatopoulos +Steenken +Stephane +Streif +Sukin +Takita +Tanvi +Tapp +Technol +Temme +Toeplitz +Toffoli +Tommaso +Trackerservice +Trotterization +Trotterize +Trotterizing +Vadim +Vedran +Ville +Vion +Vivek +Vojtech +Volkoff +Weedbrook +Wierichs +Woerner +Wootton +Youngseok +Yousef +Yunchao +Yung +Zeilinger +Zeng +Zhou +Zoufal +addon +anharmonic +ansatz +ansatzes +arXiv +autoencoder +autoencoders +backend's +bilinearity +bitstring +bool +colocated +coprime +decohere +disproven +doi +ebit +eigenbasis +eigensolver +eigensolvers +eigenstate +eigenstates +endian +exponentials +expressibility +fanout +fermionic +fidelities +hyperparameter +hyperparameters +ket +kets +minimax +misclassifying +multilinear +namespace +nucleobase +orthogonalization +orthonormality +parameterization +polynomially +preprint +priori +pseudocode +qiskit +quantizing +quasiprobabilities +quasiprobability +qubit +qubit's +qubits +qudit +qutrits +recalibrated +reuploading +satisfiability +simulability +subfield +subfields +subscripting +substring +substrings +sudoku +summand +summands +tooltip +tooltips +transmon +transpilation +transpile +transpiled +transpiler +transpiler's +transpiling +tridiagonal +trits +unitaries diff --git a/test/docs/vale.sh b/test/docs/vale.sh new file mode 100755 index 000000000..f4bd36416 --- /dev/null +++ b/test/docs/vale.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +cd ./docs + +vale . + +echo +echo "Linting notebooks using nbQA:" + +notebooks=$(find . -name "*.ipynb" -not -name "*checkpoint*" -not -path "./_**") + +python -m nbqa vale ${notebooks} --nbqa-shell --nbqa-md