Add the missing built-in constant-expression functions (`popcount`, `rotl`, `rotr`, `mod`, `exp`, `log`, `pow`, `ceiling`, `floor`)
メンテナーはふだん 1 日以内に返信
評価
調査の方向性
Start in src/pyqasm/maps/expressions.py, where FUNCTION_MAP is defined near line 196, and check how existing entries such as sqrt are applied in constant and gate-argument contexts. Reproduce with the pyqasm.loads(...).validate() snippets in the issue. Done means ceiling, floor, exp, log and mod validate in both const declarations and gate arguments, with tests added in tests/qasm3/test_expressions.py. Leave popcount, rotl, rotr and pow for a maintainer to scope, since they depend on a companion issue and an upstream parser problem.
索引モデルが issue の本文から書いたものです。
説明
Limitation
Table 2 — Built-in mathematical functions
lists the functions every OpenQASM 3 implementation must provide in constant expressions:
arccos, arcsin, arctan, ceiling, cos, exp, floor, log, mod, popcount,
pow, rotl, rotr, sin, sqrt, tan.
pyqasm's FUNCTION_MAP provides only abs, real, imag, sqrt, sin, cos, tan,
arccos, arcsin, arctan. Nine of the spec's functions are missing:
ceiling, floor, exp, log, mod, popcount, pow, rotl, rotr.
Example QASM failure
Every one of these is a valid constant expression per the spec:
import pyqasm
for decl in [
"const uint c = popcount(37);",
'const bit[8] c = rotl("00101010", 3);',
'const bit[8] c = rotr("00101010", 3);',
"const int c = mod(7, 2);",
"const float[64] c = exp(1.0);",
"const float[64] c = log(2.0);",
"const int c = ceiling(1.2);",
"const int c = floor(1.8);",
]:
m = pyqasm.loads("OPENQASM 3.0;\n" + decl)
m.validate()
ValidationError: Invalid initialization value for constant 'c'
They fail as gate arguments too, where sqrt already works:
OPENQASM 3.0;
include "stdgates.inc";
qubit[1] q;
rx(sqrt(2.0)) q[0]; // OK today
rx(exp(1.0)) q[0]; // ValidationError: Invalid parameter 'exp(1.0)' for gate 'rx'
The spec's own example under Built-in constant expression functions exercises most of them:
const float[64] f2 = 2.0 * exp(f1);
const int[8] i2 = pow(i1, u1);
const bit[8] b2 = rotl(b1, 3);
Change Requested
- Add
ceiling,floor,exp,log,modtoFUNCTION_MAPwith the spec's signatures. - Add
popcount,rotl,rotr, which operate onbit[n]anduint[n]and must preserve
the input width. - Add
pow(a, b)as a function. Note the parser caveat below — this one is not purely a
FUNCTION_MAPentry. - Report an unknown function name and an arity or type mismatch as a
ValidationErrornaming
the function, rather than the current generic"Invalid initialization value"message,
which gives the user no indication that the function was the problem.
Implementation Details
FUNCTION_MAPis insrc/pyqasm/maps/expressions.py:196. Most additions are one line each:
"exp": np.exp,"log": np.log,"ceiling": np.ceil,"floor": np.floor,
"mod": np.mod.popcount/rotl/rotrare defined onbit[n]and depend on a width-carrying bit
representation — see the companion issue onbit[n]operators. Widths must be preserved:
rotl(a, n) == rotr(a, -n), and the output width equals the input width.powhas a known blocker.const int c = pow(2, 3);fails at parse time in
openqasm31.0.1 becausepowis also the gate-modifier keyword. Verify against the
current upstream release and, if it still reproduces, open an issue on
openqasm/openqasmand link it here; the pyqasm-side change can land independently for the
other eight functions.- Spec overload resolution matters for the error messages:
pow(int, uint) -> intis
preferred overpow(float, float) -> float, which is preferred over thecomplexoverload.
expandsqrteach havefloat -> floatandcomplex -> complexforms. - Tests:
tests/qasm3/test_expressions.py— one case per function covering aconst
declaration and a gate argument, plus arity and type-error cases.
- 主要言語
- Python
- スター
- 29
- フォーク
- 33
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 15
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
qBraid/pyqasm のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 63/100
メンテナーはふだん 1 日以内に返信
-
enhancement error-handling program-validation
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 1 日以内に返信
-
Move the QASM 2 printer and its branch pre-processing out of qasm2.py対応中かも @danielgaskins が 7 日前に担当しました。 オープンenhancement qasm2
難易度 4/5 3〜5日 初心者へのやさしさ 22/100
qBraid/pyqasm#447 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
[BUG] dumps() emits extern calls without a semicolon, producing unparsable QASM対応中かも @Jah-yee が 16 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 25/100
qBraid/pyqasm#438 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Parse failures raise ValidationError with an empty message; the ANTLR diagnostic is lost対応中かも @tonycoder-hub が 9 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 22/100
qBraid/pyqasm#436 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
-
[Bug]: Queen's own Ollama model loses num_ctx when a running session switches to it対応中かも @anasamin26 が今日担当しました。 オープンbug enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
aden-hive/hive#7508 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
llm translation
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
BerriAI/litellm#47884 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
bug 🐛
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
netalertx/NetAlertX#1856 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信