{"id":20131271,"url":"https://github.com/glassnotes/caspar","last_synced_at":"2025-04-09T16:40:37.177Z","repository":{"id":85604721,"uuid":"98993503","full_name":"glassnotes/Caspar","owner":"glassnotes","description":"SU(n) factorization in Python.","archived":false,"fork":false,"pushed_at":"2017-08-03T07:37:48.000Z","size":212,"stargazers_count":5,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-23T18:52:10.729Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/glassnotes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-08-01T11:23:21.000Z","updated_at":"2021-12-09T21:57:03.000Z","dependencies_parsed_at":null,"dependency_job_id":"feb3e524-074d-4f65-849b-0656b73cc234","html_url":"https://github.com/glassnotes/Caspar","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glassnotes%2FCaspar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glassnotes%2FCaspar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glassnotes%2FCaspar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glassnotes%2FCaspar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/glassnotes","download_url":"https://codeload.github.com/glassnotes/Caspar/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248068871,"owners_count":21042571,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T20:47:12.532Z","updated_at":"2025-04-09T16:40:37.156Z","avatar_url":"https://github.com/glassnotes.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Caspar \nA Python implementation of the SU(_n_) factorization scheme of \u003ca href=\"http://arxiv.org/abs/1708.00735\" target=\"_blank\"\u003earXiv:1708.00735\u003c/a\u003e.\n\nIf you run into any trouble, or find a bug, feel free to drop me a line at\nodimatte@uwaterloo.ca or create an issue in the repo.\n                                                                                   \n## Dependencies                                                                    \n                                                                                   \nYou will need the numpy package. Caspar was developed using Python 3.5.2 but\nalso was tested and runs smoothly in 2.7.10. \n\n## Installation\n\nIn the main directory of the folder, type `python setup.py install`.\n                                                                                   \n## Usage (basic)\n\nThere are two important files: `factorization_script.py`, and `user_matrix.py`. \nEnter the SU(_n_) matrix you wish to factorize in the variable `SUn_mat` in \n`user_matrix.py`. Then, factorize it by running \n```\npython factorization_script.py\n```\n\nThe output of this script will be a series of lines in the following format, for example:\n```\n4,5    [-2.8209, 2.5309, 2.3985]\n3,4    [-1.7534, 1.4869, -1.753]\n...\n```\nThis is a sequence of SU(2) transformations. The first two integers indicate \nthe modes on which the transformation acts. The set of three floats are the \nparameters of the transformation (see parametrization below). \nThe original matrix `SUn_mat` is obtained by embedding each SU(2) transformation \ninto the indicated modes of an SU(_n_) transformation, and multiplying them \ntogether from top to bottom of the list (with each transformation added to \nthe product on the right, e.g. _U_ = _U_\u003csub\u003e45\u003c/sub\u003e _U_\u003csub\u003e34\u003c/sub\u003e...).  \n\n## Important usage notes\n\nAt the time of writing...\n- For sparser matrices, such as the _m_-qubit Paulis, Caspar has seen good \n  success up to 6 qubits (n = 2^6 = 64, and this is just as high as I tested).\n- For denser Haar-random unitaries, Caspar works well for up to about _n_ = 10 \n  before it begins to suffer from issues due to numerical precision. You can \n  use the function `sun_reconstruction` to compare the original matrix to the\n  one reconstructed by the parameters that Caspar outputs (see below).\n  \n\n\n## Usage (detailed)\n                                                         \nAn arbitrary element of SU(_n_) can be fully expressed using at most \n_n_\u003csup\u003e2\u003c/sup\u003e - 1 parameters. We put forth a factorization scheme that \ndecomposes elements of SU(_n_) as a sequence of SU(2) transformations. \nSU(2) transformations require in general 3 parameters, [_a_, _b_, _g_], \nwritten in matrix form as  [[_e_\u003csup\u003e_i_(_a_+_g_)/2\u003c/sup\u003e cos(_b_/2), \n-_e_\u003csup\u003e_i_(_a_-_g_)/2\u003c/sup\u003e sin(_b_/2)], \n[_e_\u003csup\u003e-_i_(_a_-_g_)/2\u003c/sup\u003e sin(_b_/2), _e_\u003csup\u003e_i_(_a_+_g_)/2\u003c/sup\u003e cos(_b_/2)]].\n                                                                                   \nThere are two main functions: `sun_factorization` and `sun_reconstruction`, \neach contained in the appropriately named files.\n                                                                                   \nThe function `sun_factorization` takes an SU(_n_) matrix (as a numpy matrix) \nand decomposes it into a sequence of _n_(_n_-1)/2 such SU(2) transformations. \nThe full set of _n_\u003csup\u003e2\u003c/sup\u003e - 1 parameters is returned as a list of tuples \nof the form (\"_i_,_i_+1\", [_a_\u003csub\u003e_k_\u003c/sub\u003e, _b_\u003csub\u003e_k_\u003c/sub\u003e, _g_\u003csub\u003e_k_\u003c/sub\u003e]) \nwhere _i_ and _i_+1 indicate the modes on which the transformation acts (our\nfactorization uses transformations only on adjacent modes).\n\nThe following code snippet can be used to factorize the SU(3) matrix below.\n\n```python\nimport numpy as np\nfrom caspar import sun_factorization \n\nn = 3\n\nSUn_mat = np.matrix([[0., 0., 1.],                                               \n                    [np.exp(2 * 1j * np.pi/ 3), 0., 0.],                        \n                    [0., np.exp(-2 * 1j * np.pi / 3), 0.]])    \n\n# Perform the decomposition\nparameters = sun_factorization(SUn_mat)\n\n# The output produced is \n#\n# Factorization parameters: \n#   2,3    [2.0943951023931953, 0.0, 2.0943951023931953]\n#   1,2    [0.0, 3.1415926535897931, 0.0]\n#   2,3    [0.0, 3.1415926535897931, 0.0]\n```\n\nIt is also possible to reconstruct an SU(_n_) transformation based on a list \nof parameters for SU(2) transformations given in the form \n(\"_i_,_i_+1\", [_a_\u003csub\u003e_k_\u003c/sub\u003e, _b_\u003csub\u003e_k_\u003c/sub\u003e, _g_\u003csub\u003e_k_\u003c/sub\u003e]). \nThe matrix is computed by multiplication on the right. At the moment only \nadjacent mode transformations are supported.\n```python\nfrom caspar import sun_reconstruction\n\nparameters = [(\"1,2\", [1.23, 2.34, 0.999]), \n              (\"4,5\", [0.3228328, 0.23324, -0.2228])]\n\nnew_SUn_mat = sun_reconstruction(6, parameters)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglassnotes%2Fcaspar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fglassnotes%2Fcaspar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglassnotes%2Fcaspar/lists"}