From 1680606c279c8c7227f922b4876a78f40379ec44 Mon Sep 17 00:00:00 2001 From: Philippe Faist Date: Fri, 30 Sep 2022 09:27:05 +0200 Subject: [PATCH] sort contributors chronologically on team page --- generate_ecc_zoo.py | 50 +++++++++++++++++-- poetry.lock | 14 +++++- pyproject.toml | 1 + schemas/ecc.yml | 7 +++ test/test_code_yml_features/codes/CSS.yml | 20 +++++++- .../codes/binary_linear.yml | 9 ++-- .../codes/qubits_into_qubits.yml | 7 ++- .../codes/stabilizer.yml | 7 ++- test/test_code_yml_features/codes/surface.yml | 8 ++- .../test_code_yml_features/codes/testcode.yml | 7 ++- 10 files changed, 118 insertions(+), 12 deletions(-) diff --git a/generate_ecc_zoo.py b/generate_ecc_zoo.py index d6c90a9..0552340 100644 --- a/generate_ecc_zoo.py +++ b/generate_ecc_zoo.py @@ -10,6 +10,8 @@ import logging +import dateutil.parser + sys.path.insert(0, '.') import ecczoogen ecczoogen.setup_logging(level=logging.INFO) @@ -581,16 +583,58 @@ def _llm_as_text(s): with open(contributors_yml_fname, encoding='utf-8') as f: loaded_zoo_contributors_info = yaml.safe_load(f) for user in loaded_zoo_contributors_info: - zooteam = user.get('zooteam', 'code_contributors') + zooteam = user.get('zooteam', None) #'code_contributors') # make sure user_id is unique user_id = user['user_id'] if user_id in zoo_users_db: logger.error(f"User ID {user_id} was assigned twice!\n%r\n%r", zoo_users_db[user_id], user) raise ValueError(f"User ID {user_id} was assigned twice!") + + # will store the user's contributions in this array + user['_code_contributions'] = [] + zoo_users_db[user_id] = user - # sort into the correct team - zoo_contributors_info[zooteam].append(user) + + if zooteam is not None: + # sort into the correct team (code contributors will automatically + # be added later) + zoo_contributors_info[zooteam].append(user) + + +# collect contributions for each user +for code_id, code in zoo.all_codes().items(): + if '_meta' in code.source_info: + if 'changelog' in code.source_info['_meta']: + for chg in code.source_info['_meta']['changelog']: + user = zoo_users_db[chg['user_id']] + user['_code_contributions'].append({ + 'changelog_item': chg, + 'code': code, + }) + if 'zooteam' not in user: + user['zooteam'] = 'code_contributors' + zoo_contributors_info['code_contributors'].append(user) + +# +# Now, sort the code contributors by chronological order of contributions +# +def get_user_earliest_contribution_dt(user): + earliest_dt = None + earliest_contrib = None + for contrib in user['_code_contributions']: + chgdt = dateutil.parser.parse(contrib['changelog_item']['date']) + if earliest_dt is None or chgdt < earliest_dt: + earliest_dt = chgdt + earliest_contrib = contrib + if earliest_contrib is None: + raise RuntimeError(f"?? user {user!r} has no contributions despite being " + f"in the code_contributors team") + return earliest_dt + +zoo_contributors_info['code_contributors'].sort( + key=get_user_earliest_contribution_dt +) # diff --git a/poetry.lock b/poetry.lock index 2ab19b3..2c1a2f8 100644 --- a/poetry.lock +++ b/poetry.lock @@ -252,6 +252,17 @@ category = "main" optional = false python-versions = ">=3.7" +[[package]] +name = "python-dateutil" +version = "2.8.2" +description = "Extensions to the standard Python datetime module" +category = "main" +optional = false +python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,>=2.7" + +[package.dependencies] +six = ">=1.5" + [[package]] name = "python-frontmatter" version = "1.0.0" @@ -360,7 +371,7 @@ testing = ["pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest- [metadata] lock-version = "1.1" python-versions = "^3.8" -content-hash = "17beee1684ea4c0394b3133dcce7314de559f00819b18f65e082d7dda2c162a1" +content-hash = "b8665f256a894c44cef4b0e7f61fdc19271a032e7b5ca0f0b0f14daf9e1d4f9e" [metadata.files] arxiv = [] @@ -384,6 +395,7 @@ markupsafe = [] pillow = [] pylatexenc = [] pyrsistent = [] +python-dateutil = [] python-frontmatter = [] pyyaml = [] requests = [] diff --git a/pyproject.toml b/pyproject.toml index 212a2a5..205f9a5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,6 +21,7 @@ backoff = "^1.11.1" citeproc-py = {'git' = "https://github.com/phfaist/citeproc-py.git"} Pillow = "^9.0.1" "ruamel.yaml" = "^0.17.21" +python-dateutil = "^2.8.2" [tool.poetry.dev-dependencies] diff --git a/schemas/ecc.yml b/schemas/ecc.yml index 2d376fd..468de7c 100644 --- a/schemas/ecc.yml +++ b/schemas/ecc.yml @@ -30,6 +30,13 @@ _zoo_relations: #relation_primary_key_field: 'code_id' #relation_object_field: 'code' + - object_field: '_meta.changelog' + to_object_type: 'user' + relation_primary_key_field: 'user_id' + relation_add_object_field: 'user' + backreference: + field: 'zoo_contributions.code' + properties: diff --git a/test/test_code_yml_features/codes/CSS.yml b/test/test_code_yml_features/codes/CSS.yml index 5dd24d0..92ad7cb 100644 --- a/test/test_code_yml_features/codes/CSS.yml +++ b/test/test_code_yml_features/codes/CSS.yml @@ -25,6 +25,13 @@ description: | \end{align} The above condition guarantees that the \(X\)-stabilizer generators, defined in the symplectic representation as rows of \(H_X\), commute with the \(Z\)-stabilizer generators associated with \(H_Z\). + \begin{table} + \begin{cells} + \celldata{One\\ Two\\ Three} + \celldata[1-;2]{1\\ 2\\ 3} + \end{cells} + \end{table} + Encoding is based on two related \hyperref[code:binary_linear]{binary linear codes}, an \([n,k_X,d^\prime_X]\) code \(C_X\) and \([n,k_Z,d^\prime_Z]\) code \(C_Z\), satisfying \(C_X^\perp \subseteq C_Z\). The resulting CSS code has \(k=k_X+k_Z-n\) logical qubits and distance \(d\geq\min\{d^\prime_X,d^\prime_Z\}\). The \(H_X\) (\(H_Z\)) block of \(H\) \eqref{eq:parity} is the parity-check matrix of the code \(C_X\) (\(C_Z\)). The requirement \(C_X^\perp \subseteq C_Z\) guarantees \eqref{eq:comm}. Basis states for the code are, for \(\gamma \in C_X\), \begin{align} @@ -96,4 +103,15 @@ relations: _meta: - contributors: [] + changelog: + - user_id: PhF + date: '2022-03-05' + notes: 'These logs are completely fictitious!' + - user_id: PhF + date: '2021-01-01' + + + + + + diff --git a/test/test_code_yml_features/codes/binary_linear.yml b/test/test_code_yml_features/codes/binary_linear.yml index a7a9f99..d182d4b 100644 --- a/test/test_code_yml_features/codes/binary_linear.yml +++ b/test/test_code_yml_features/codes/binary_linear.yml @@ -42,6 +42,9 @@ notes: # Begin Entry Meta Information _meta: - contributors: - - name: 'Victor V. Albert' - githubusername: valbert4 + changelog: + - user_id: VVA + date: '2022-03-05' + notes: 'These logs are completely fictitious' + - user_id: VVA + date: '2021-01-01' diff --git a/test/test_code_yml_features/codes/qubits_into_qubits.yml b/test/test_code_yml_features/codes/qubits_into_qubits.yml index dc76341..4725c5c 100644 --- a/test/test_code_yml_features/codes/qubits_into_qubits.yml +++ b/test/test_code_yml_features/codes/qubits_into_qubits.yml @@ -27,4 +27,9 @@ description: 'Encodes \(K\)-dimensional Hilbert space into a \(2^n\)-dimensional # detail: 'code_id4 are other codes of similar encoding but with different physical space structures (classical or quantum)' _meta: - contributors: [] + changelog: + - user_id: PhF + date: '2022-03-05' + notes: 'These logs are completely fictitious' + - user_id: VVA + date: '2021-01-01' diff --git a/test/test_code_yml_features/codes/stabilizer.yml b/test/test_code_yml_features/codes/stabilizer.yml index 5cbeded..865bb81 100644 --- a/test/test_code_yml_features/codes/stabilizer.yml +++ b/test/test_code_yml_features/codes/stabilizer.yml @@ -35,4 +35,9 @@ relations: _meta: - contributors: [] + changelog: + - user_id: PhF + date: '2022-03-05' + notes: 'These logs are completely fictitious' + - user_id: VVA + date: '2021-01-01' diff --git a/test/test_code_yml_features/codes/surface.yml b/test/test_code_yml_features/codes/surface.yml index b4320e8..12104df 100644 --- a/test/test_code_yml_features/codes/surface.yml +++ b/test/test_code_yml_features/codes/surface.yml @@ -72,4 +72,10 @@ relations: _meta: - contributors: [] + changelog: + - user_id: VVA + date: '2022-03-05' + notes: 'These logs are completely fictitious' + - user_id: VVA + date: '2021-01-01' + diff --git a/test/test_code_yml_features/codes/testcode.yml b/test/test_code_yml_features/codes/testcode.yml index 8f12c1d..bd4b84c 100644 --- a/test/test_code_yml_features/codes/testcode.yml +++ b/test/test_code_yml_features/codes/testcode.yml @@ -169,4 +169,9 @@ relations: detail: 'Description of how this code relates to stabilizer codes.\cite{arXiv:1111.0011}' _meta: - contributors: [] + changelog: + - user_id: PhF + date: '2022-03-05' + notes: 'These logs are completely fictitious' + - user_id: VVA + date: '2021-01-01'