{"id":19146457,"url":"https://github.com/kahsolt/tiny-q","last_synced_at":"2026-03-04T06:33:12.766Z","repository":{"id":143462606,"uuid":"614676128","full_name":"Kahsolt/Tiny-Q","owner":"Kahsolt","description":"Tiny-Q is a minimal framework to show quantum computation basics in a tensor/matrix perspective view.","archived":false,"fork":false,"pushed_at":"2024-07-03T11:08:34.000Z","size":189,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-27T09:57:21.343Z","etag":null,"topics":["educational","quantum-computing","tutorial"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Kahsolt.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-03-16T04:39:20.000Z","updated_at":"2024-07-03T11:08:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"dc71fc61-54b7-45b3-80fc-e837f2793503","html_url":"https://github.com/Kahsolt/Tiny-Q","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/Kahsolt/Tiny-Q","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kahsolt%2FTiny-Q","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kahsolt%2FTiny-Q/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kahsolt%2FTiny-Q/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kahsolt%2FTiny-Q/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kahsolt","download_url":"https://codeload.github.com/Kahsolt/Tiny-Q/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kahsolt%2FTiny-Q/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30074182,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-04T05:31:57.858Z","status":"ssl_error","status_checked_at":"2026-03-04T05:31:38.462Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["educational","quantum-computing","tutorial"],"created_at":"2024-11-09T07:44:11.937Z","updated_at":"2026-03-04T06:33:12.735Z","avatar_url":"https://github.com/Kahsolt.png","language":"Python","readme":"# Tiny-Q\n\n    Tiny-Q is a minimal framework to show quantum computation basics in a tensor/matrix perspective view.\n\n----\n\n![demo](img/demo.png)\n\n\n### Install\n\n⚪ From PyPI\n\nℹ Due to the name conflict with an [existing pypi package](https://pypi.org/project/TinyQ/), you have to address `TinyQSim` rather than `TinyQ` :(\n\n- `pip install TinyQSim`\n\n⚪ From source\n\n- `git clone https://github.com/Kahsolt/Tiny-Q`\n- `cd Tiny-Q`\n- `pip install .`\n- you can see [exmaples](/examples/) or run `run_unnittest.cmd` to verify installation\n\n\n### Features\n\n⚪ Tiny-Q interactive playground\n\nStart interactive python shell with Tiny-Q environment: `python -m tiny_q`\n\n```python\n(InteractiveConsole)\n\u003e\u003e\u003e v('00')\narray([1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], dtype=complex64)\n\u003e\u003e\u003e H\narray([[ 0.7071+0.j,  0.7071+0.j],\n       [ 0.7071+0.j, -0.7071+0.j]], dtype=complex64)\n\u003e\u003e\u003e CNOT\narray([[1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],\n       [0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j],\n       [0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j],\n       [0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j]], dtype=complex64)\n\u003e\u003e\u003e q = CNOT * (H @ I) | v('00')\n\u003e\u003e\u003e q.info()\n|phi\u003e\n  state: [0.7071+0.j 0.    +0.j 0.    +0.j 0.7071+0.j]\n  amp: [0.7071 0.     0.     0.7071]\n  prob: [0.5 0.  0.  0.5]\n  density: [[0.5+0.j 0. +0.j 0. +0.j 0.5+0.j]\n [0. +0.j 0. +0.j 0. +0.j 0. +0.j]\n [0. +0.j 0. +0.j 0. +0.j 0. +0.j]\n [0.5+0.j 0. +0.j 0. +0.j 0.5+0.j]]\n  trace: (0.99999994+0j)\n\n\u003e\u003e\u003e q \u003e Measure()\n{'00': 489, '01': 0, '10': 0, '11': 511}\n\u003e\u003e\u003e q \u003c Measure\n\u003e\u003e\u003e q.info()\n|phi\u003e\n  state: [1.+0.j 0.+0.j 0.+0.j 0.+0.j]\n  amp: [1. 0. 0. 0.]\n  prob: [1. 0. 0. 0.]\n  density: [[1.+0.j 0.+0.j 0.+0.j 0.+0.j]\n [0.+0.j 0.+0.j 0.+0.j 0.+0.j]\n [0.+0.j 0.+0.j 0.+0.j 0.+0.j]\n [0.+0.j 0.+0.j 0.+0.j 0.+0.j]]\n  trace: (1+0j)\n\n\u003e\u003e\u003e Ctrl+D\nnow exiting InteractiveConsole...\n```\n\n⚪ Tiny-Q syntax / notations\n\nTiny-Q strictly distinguishes the following four categories of operations, an re-assigin each to a different python operator, making expresssions syntax formula-like thus more clear :)\n\n- `system expansion (@)` is the hadamard product\n- `gate composition (*) and gate construction (\u003c\u003c)` are the matrix product\n- `gate application (|)` is the quantum state evolution\n- `virtual measure (\u003e) and real measure (\u003c)` are the quantum measurements\n\n```python\n# use matmul @ for system expansion (gate/state tensor product)\n# u = Gate @ Gate\nu = H @ I\n# q = State @ State\nq = v0 @ v1\n# NOTE: the low qubit starts from **right**\nq = v_high @ v_mid @ v_low    # =\u003e |high,mid,low\u003e\n\n# use mul * for gate composition\n# u = Gate * Gate (more like math formula, reducing from **right**)\nu = X * H\nu = gate3 * gate2 * gate1\n# use lshift \u003c\u003c for gate construction\n# u = Gate \u003c\u003c Gate (more like programs, running from **left**, modify **inplace**)\nu = H \u003c\u003c X\nu = gate1 \u003c\u003c gate2 \u003c\u003c gate3\n\n# use pipe | for gate application\n# q = Gate | State\nq = X | v0\n# use pipe | for pauli expectation or state fidelity\n# E = State | Gate | State\nE = State.rand() | (X @ Z) | State.rand()\n# fid = State | State\nfid = (X | v('01')) | (H | v('01'))\n\n# use \u003e for virtual measure, the state does not really change\n# r = State \u003e Measure, single shot\nr = H | v0 \u003e Measure\n# r = State \u003e Measure(count), multi shots\nr = CNOT * (H @ I) | State.zero(2) \u003e Measure(1000)\n# p = State \u003e State, project by state\np = v0 \u003e h0\n# p = State \u003e MeasureOp, project by measure operator\np = h0 \u003e M0\n\n# use \u003c for real measure, the state will collapse\n# State \u003c Measure\nq = CNOT * (H @ I) | v('00')\nq \u003c Measure\n```\n\n### API stub\n\n```python\nclass Meta:\n  .n_qubits -\u003e int          # qubit count of current system\n  .dagger -\u003e Meta           # dagger of State/Gate/MeasureOp\n\nclass State(Meta):\n  .zero() -\u003e State          # alloc a |0\u003e string\n  .one() -\u003e State           # alloc a |1\u003e string\n  .rand() -\u003e State          # get a random state (usually as test stub)\n  .__eq__() -\u003e bool         # state equality (ignoring global phase)\n  .__matmul__() -\u003e State    # v0 @ v1: state expansion\n  .__lt__() -\u003e Union        # v0 \u003c Measure, real measure with state collapse\n  .__gt__() -\u003e Union        # v0 \u003e Measure|Measure()|State|MeasureOp, virtual measurements\n  .is_pure -\u003e bool          # purity\n  .amp -\u003e ndarray           # amplitude\n  .prob -\u003e ndarray          # probabilty distribution\n  .density -\u003e ndarray       # density matrix\n  .trace -\u003e float           # trace of density matrix\n  .info()                   # quick show info\n  .plot_prob()              # plot probabilty distribution\n  .plot_density()           # plot density matrix\n  .plots()                  # plot all figures\n\nclass Gate(Meta):\n  .__eq__() -\u003e bool         # gate equality\n  .__neg__() -\u003e Gate        # -H, global negative\n  .__xor__() -\u003e Gate        # H^alpha, gate self-power\n  .__mul__() -\u003e Gate        # X * H: gate composition\n  .__lshift__() -\u003e Gate     # H \u003c\u003c X: gate composition (reverse order of __mul__)\n  .__matmul__() -\u003e Gate     # X @ H: gate expansion\n  .__or__() -\u003e State        # X | v0: gate application\n  .is_unitary -\u003e bool       # unitary (should always be True)\n  .is_hermitian -\u003e bool     # hermitian (True for most gates)\n  .info()                   # quick show info\n\nclass MeasureOp(Meta):\n  .check_completeness() -\u003e bool\n```\n\n----\n\nby Armit\n2023/03/15 \n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkahsolt%2Ftiny-q","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkahsolt%2Ftiny-q","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkahsolt%2Ftiny-q/lists"}