From 88564044eedabc11645e83b47855e4e9d2756ea5 Mon Sep 17 00:00:00 2001 From: Isil Ozfidan Date: Mon, 5 Mar 2018 15:14:47 -0800 Subject: [PATCH] 4/4! - transform functions. (#232) * fixed bohr/angstrom confusion in function description * translations from mathematica to python arxiv1712.07067 * work on those notimplementeds * WIP: decoder class adittion * modified decoder class. extractor implemented * no need for pauliaction function * introduction of symbolic binary class - no more decoder class * minor bugs fixed, applies binary rules to input now * started programming the BinaryCode class, work in progress * added count qubit function in binary operator, modified code.py * fixed morning brain bugs * implemented concatination and appending, not yet documented and debugged * added _shift function to symbolicBinary and integer addition. modified the decoder shifter accordinly * radd imul, NOT TESTED! - just copy paste should work? * fixed small bugs, added default codes, created transform * fixed the multiplication error and modified the transform code following mathematica code. it was giving wrong operators before, now the operators are fine but signs are wonky * fixed the transform and all the places where we accidentally started to count qubit/fermion labels from 1 instead of 0 * bug fixes: ordering matters to detect which terms should cancel * fixed code appending, introduced the integer multiplication (left+right) as a tool to append the same code intance several times * modified the multiply by 0 and 1 behavior in SymbolicBinary. added tests for symbolicBinary. minor mods for python3 comp. * fixed the condition for code concatenation, fixed a bug in checksum_code, added an error if qubit index in a code is out of bounds * added comments to binary_operator, more test, evaluate function * started writing documentations and clipping lines, writing out numpy * merging with the merger * updating binary operator based on comments * updating the binary_ops * updates based on comments * init update * moved binaryop to first import * added names into notice and readme * started documentation in _code_operator.py, added parity code / (K=1) and (K=2) segment code / K=1 binary addressing code * encoders are sparse matrices now * added tests for code_operator * doc strings for the transform, fixed bug in the initialization of SymbolicBinary, made changes suggested by review, carried some of them over to files to be pulled later * updates based on pull request comments * merging changes with merger * fixing possible integer checking errors * cleaned version of transform function, needs testing and timing - seems to work so far * fixed BK transforms. indexing errors * added tests, pep8 and Ryan compliance mods * added some style to the functions file * renaming, re-structuring * renaming again * minor changes * pep8 * changed the symbolicBInary class * docstring cleanup * bug docstring fixes * bug fix in the evaluate method, pep8 the _binary_operator file * merge with upstream and additional tests to SymbolicBinary class * added weight-two segment code test, fixed bug with in the code appending by integer multiplication * added half-up code * bugs fixed in half-up code * corrected weight_one_segment_code and the interleaved_code, former half-up. Added tests for the codes. * get rid of heads * reordering function for the fermionOperator class. takes 0,1,2,3,4,.. -> 0,2,4,..,1,3,... * spin indexing within moleculardata * started writing demo (work in progress), corrected typo in functions test , fixed possible bug for string parsing in symbolic binary file * changed function file test such that data is obtained half-up, added last part for ipython demo * corrected typos in the demo notebook * fixed bugs in test, it now runs without error * code transforms * pep8 * transform demo * fixes * typos fixing in demo * reverting back to original demo * demo testing & indent * docstring update * not ready for review! started on docs * descriptions for code functions * final pass at docs, fixing spaces * modes to n modes, and imports * fixed a bug in demo, added description to weight-n codes --- examples/binary_code_transforms_demo.ipynb | 346 ++++++++++++++++++ .../hamiltonians/_molecular_data.py | 6 +- src/openfermion/ops/_symbolic_binary.py | 2 +- src/openfermion/tests/_example_test.py | 32 ++ src/openfermion/transforms/__init__.py | 8 + src/openfermion/transforms/_bravyi_kitaev.py | 1 + .../transforms/_code_transform_functions.py | 258 +++++++++++++ .../_code_transform_functions_test.py | 100 +++++ 8 files changed, 749 insertions(+), 4 deletions(-) create mode 100644 examples/binary_code_transforms_demo.ipynb create mode 100644 src/openfermion/transforms/_code_transform_functions.py create mode 100644 src/openfermion/transforms/_code_transform_functions_test.py diff --git a/examples/binary_code_transforms_demo.ipynb b/examples/binary_code_transforms_demo.ipynb new file mode 100644 index 000000000..ade753809 --- /dev/null +++ b/examples/binary_code_transforms_demo.ipynb @@ -0,0 +1,346 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# This code block is for automatic testing purposes, please ignore.\n", + "try:\n", + " import openfermion\n", + "except:\n", + " import os\n", + " os.chdir('../src/')" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "deletable": true, + "editable": true + }, + "source": [ + "# Lowering qubit requirements using binary codes\n", + "## Introduction\n", + "\n", + "Molecular Hamiltonians are known to have certain symmetries that are not taken into account by mappings like the Jordan-Wigner or Bravyi-Kitaev transform. The most notable of such symmetries is the conservation of the total number of particles in the system. Since those symmetries effectively reduce the degrees of freedom of the system, one is able to reduce the number of qubits required for simulation by utilizing binary codes (arXiv:1712.07067). \n", + "\n", + "We can represent the symmetry-reduced Fermion basis by binary vectors of a set $\\mathcal{V} \\ni \\boldsymbol{\\nu}$, with $ \\boldsymbol{\\nu} = (\\nu_0, \\, \\nu_1, \\dots, \\, \\nu_{N-1} ) $, where every component $\\nu_i \\in \\lbrace 0, 1 \\rbrace $ and $N$ is the total number of Fermion modes. These binary vectors $ \\boldsymbol{\\nu}$ are related to the actual basis states by: $$\n", + "\\left[\\prod_{i=0}^{N-1} (a_i^{\\dagger})^{\\nu_i} \\right] \\left|{\\text{vac}}\\right\\rangle \\, ,\n", + "$$ where $ (a_i^\\dagger)^{0}=1$. The qubit basis, on the other hand, can be characterized by length-$n$ binary vectors $\\boldsymbol{\\omega}=(\\omega_0, \\, \\dots , \\, \\omega_{n-1})$, that represent an $n$-qubit basis state by:\n", + "$$ \\left|{\\omega_0}\\right\\rangle \\otimes \\left|\\omega_1\\right\\rangle \\otimes \\dots \\otimes \\left|{\\omega_{n-1}}\\right\\rangle \\, . $$ \n", + "Since $\\mathcal{V}$ is a mere subset of the $N$-fold binary space, but the set of the vectors $\\boldsymbol{\\omega}$ spans the entire $n$-fold binary space we can assign every vector $\\boldsymbol{\\nu}$ to a vector $ \\boldsymbol{\\omega}$, such that $n