From 8b6091ad2f9ea13300bacd5d80b377bd0913b1ee Mon Sep 17 00:00:00 2001 From: Jonhas Colina Date: Mon, 11 Aug 2025 14:35:07 -0400 Subject: [PATCH 1/6] added missing arg shot_id --- python/quantum-pecos/src/pecos/engines/cvm/classical.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/python/quantum-pecos/src/pecos/engines/cvm/classical.py b/python/quantum-pecos/src/pecos/engines/cvm/classical.py index 74d5c75bf..c4ad9e991 100644 --- a/python/quantum-pecos/src/pecos/engines/cvm/classical.py +++ b/python/quantum-pecos/src/pecos/engines/cvm/classical.py @@ -221,23 +221,23 @@ def recur_eval_op( c = expr_dict.get("c") if isinstance(a, dict): - a = recur_eval_op(a, output, width) + a = recur_eval_op(a, output, width, shot_id=shot_id) elif c: # c => unary operation c = ( - recur_eval_op(c, output, width) + recur_eval_op(c, output, width, shot_id=shot_id) if isinstance(c, dict) else get_val(c, output, width, shot_id) ) - a = eval_op(op, c, width=width, shot_id=shot_id) + a = eval_op(op, c, width=width) else: a = get_val(a, output, width, shot_id) if b: b = ( - recur_eval_op(b, output, width) + recur_eval_op(b, output, width, shot_id=shot_id) if isinstance(b, dict) else get_val(b, output, width, shot_id) ) From 74a9006d0b26bd203aa0ee0220783544354b5c9c Mon Sep 17 00:00:00 2001 From: Jonhas Colina Date: Thu, 14 Aug 2025 16:05:54 -0400 Subject: [PATCH 2/6] job shot num ptch --- python/quantum-pecos/src/pecos/engines/cvm/classical.py | 3 +-- python/quantum-pecos/src/pecos/engines/hybrid_engine_old.py | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/python/quantum-pecos/src/pecos/engines/cvm/classical.py b/python/quantum-pecos/src/pecos/engines/cvm/classical.py index c4ad9e991..b68d202b5 100644 --- a/python/quantum-pecos/src/pecos/engines/cvm/classical.py +++ b/python/quantum-pecos/src/pecos/engines/cvm/classical.py @@ -361,9 +361,8 @@ def eval_condition( a = conditional_expr["a"] b = conditional_expr["b"] op = conditional_expr["op"] - if isinstance(a, str): - a = output[a] # str -> BinArray + a = output[a] # str -> BinArray elif isinstance(a, tuple | list) and len(a) == 2: a = output[a[0]][a[1]] # (str, int) -> int (1 or 0) else: diff --git a/python/quantum-pecos/src/pecos/engines/hybrid_engine_old.py b/python/quantum-pecos/src/pecos/engines/hybrid_engine_old.py index 87cd1d9b1..816ed699e 100644 --- a/python/quantum-pecos/src/pecos/engines/hybrid_engine_old.py +++ b/python/quantum-pecos/src/pecos/engines/hybrid_engine_old.py @@ -129,6 +129,7 @@ def run( Tuple of final simulator state and output dictionary. """ output = set_output(state, circuit, output_spec, output) + output['JOB_shotnum'] = self.rng_model.shot_id output_export = {} self.circuit = circuit From 0fdefbe57fd8a37e26eacafcf1aa34d96cac5a35 Mon Sep 17 00:00:00 2001 From: Jonhas Colina Date: Thu, 14 Aug 2025 16:24:05 -0400 Subject: [PATCH 3/6] fix --- python/quantum-pecos/src/pecos/engines/hybrid_engine_old.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/quantum-pecos/src/pecos/engines/hybrid_engine_old.py b/python/quantum-pecos/src/pecos/engines/hybrid_engine_old.py index 816ed699e..0f21401f4 100644 --- a/python/quantum-pecos/src/pecos/engines/hybrid_engine_old.py +++ b/python/quantum-pecos/src/pecos/engines/hybrid_engine_old.py @@ -129,7 +129,7 @@ def run( Tuple of final simulator state and output dictionary. """ output = set_output(state, circuit, output_spec, output) - output['JOB_shotnum'] = self.rng_model.shot_id + output['JOB_shotnum'] = shot_id output_export = {} self.circuit = circuit From 46496f6260d0147015f50e78ee618dc32f4ca5d2 Mon Sep 17 00:00:00 2001 From: Jonhas Colina Date: Thu, 14 Aug 2025 16:29:55 -0400 Subject: [PATCH 4/6] added test file --- .../regression_qasm/RNGnum_mod_h5.qasm | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 python/tests/pecos/regression/test_qasm/regression_qasm/RNGnum_mod_h5.qasm diff --git a/python/tests/pecos/regression/test_qasm/regression_qasm/RNGnum_mod_h5.qasm b/python/tests/pecos/regression/test_qasm/regression_qasm/RNGnum_mod_h5.qasm new file mode 100644 index 000000000..4a45aae2a --- /dev/null +++ b/python/tests/pecos/regression/test_qasm/regression_qasm/RNGnum_mod_h5.qasm @@ -0,0 +1,35 @@ +OPENQASM 2.0; +include "qelib1.inc"; +qreg q[5]; +creg c[5]; + +creg cond1[32]; +creg hgates1[4]; + +///////////////////////////////////////////// +// Test RNG functions with jobvar index +///////////////////////////////////////////// + +RNGseed(1000); +RNGbound(16); +RNGindex(JOB_shotnum); + +h q; +hgates1[0] = 1; + +cond1 = RNGnum(); +cond1 = cond1 % 7; +if (cond1[0] != 0) h q; +if (cond1[0] != 0) hgates1[1] = 1; + +cond1 = RNGnum(); +cond1 = cond1 % 7; +if (cond1[1] != 0) h q; +if (cond1[1] != 0) hgates1[2] = 1; + +cond1 = RNGnum(); +cond1 = cond1 % 7; +if (cond1[3] != 0) h q; +if (cond1[3] != 0) hgates1[3] = 1; + +measure q->c; From da3e99ae44a31b6fe7d97ce5c6d1749825b36f07 Mon Sep 17 00:00:00 2001 From: Jonhas Colina Date: Thu, 14 Aug 2025 16:52:15 -0400 Subject: [PATCH 5/6] cleanup --- python/quantum-pecos/src/pecos/engines/cvm/classical.py | 2 +- python/quantum-pecos/src/pecos/engines/hybrid_engine_old.py | 2 +- .../test_qasm/regression_qasm/RNGnum_jobvar_h5.qasm | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/python/quantum-pecos/src/pecos/engines/cvm/classical.py b/python/quantum-pecos/src/pecos/engines/cvm/classical.py index b68d202b5..3ef26c357 100644 --- a/python/quantum-pecos/src/pecos/engines/cvm/classical.py +++ b/python/quantum-pecos/src/pecos/engines/cvm/classical.py @@ -285,7 +285,7 @@ def eval_cop( # Eval assignment # --------------- - expr_eval = recur_eval_op(cop_expr, output, width, shot_id) + expr_eval = recur_eval_op(cop_expr, output, width, shot_id=shot_id) # Assign the final value: # ----------------------- diff --git a/python/quantum-pecos/src/pecos/engines/hybrid_engine_old.py b/python/quantum-pecos/src/pecos/engines/hybrid_engine_old.py index 0f21401f4..b7f0c29bb 100644 --- a/python/quantum-pecos/src/pecos/engines/hybrid_engine_old.py +++ b/python/quantum-pecos/src/pecos/engines/hybrid_engine_old.py @@ -267,7 +267,7 @@ def run_circuit( params.get("expr"), output, width=self.regwidth, - shot_id=self.rng_model.shot_id, + shot_id = self.rng_model.shot_id ) elif params.get("cop_type") == "ExportCVar": diff --git a/python/tests/pecos/regression/test_qasm/regression_qasm/RNGnum_jobvar_h5.qasm b/python/tests/pecos/regression/test_qasm/regression_qasm/RNGnum_jobvar_h5.qasm index 386253c88..c4d66059c 100644 --- a/python/tests/pecos/regression/test_qasm/regression_qasm/RNGnum_jobvar_h5.qasm +++ b/python/tests/pecos/regression/test_qasm/regression_qasm/RNGnum_jobvar_h5.qasm @@ -16,6 +16,10 @@ RNGindex(JOB_shotnum); h q; hgates1[0] = 1; +if (JOB_shotnum == 2) h q; +if (JOB_shotnum == 4) h q; +cond1 = JOB_shotnum + JOB_shotnum + 10; +if (cond1 == 4) h q; cond1 = RNGnum(); if (cond1[0] != 0) h q; From fd426bfff09dbbbc51cb04880c8824789142396a Mon Sep 17 00:00:00 2001 From: ciaranra Date: Fri, 15 Aug 2025 07:08:11 -0600 Subject: [PATCH 6/6] Lint --- python/quantum-pecos/src/pecos/engines/cvm/classical.py | 2 +- python/quantum-pecos/src/pecos/engines/hybrid_engine_old.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/python/quantum-pecos/src/pecos/engines/cvm/classical.py b/python/quantum-pecos/src/pecos/engines/cvm/classical.py index 3ef26c357..4e4f4f962 100644 --- a/python/quantum-pecos/src/pecos/engines/cvm/classical.py +++ b/python/quantum-pecos/src/pecos/engines/cvm/classical.py @@ -362,7 +362,7 @@ def eval_condition( b = conditional_expr["b"] op = conditional_expr["op"] if isinstance(a, str): - a = output[a] # str -> BinArray + a = output[a] # str -> BinArray elif isinstance(a, tuple | list) and len(a) == 2: a = output[a[0]][a[1]] # (str, int) -> int (1 or 0) else: diff --git a/python/quantum-pecos/src/pecos/engines/hybrid_engine_old.py b/python/quantum-pecos/src/pecos/engines/hybrid_engine_old.py index b7f0c29bb..28016cdbb 100644 --- a/python/quantum-pecos/src/pecos/engines/hybrid_engine_old.py +++ b/python/quantum-pecos/src/pecos/engines/hybrid_engine_old.py @@ -129,7 +129,7 @@ def run( Tuple of final simulator state and output dictionary. """ output = set_output(state, circuit, output_spec, output) - output['JOB_shotnum'] = shot_id + output["JOB_shotnum"] = shot_id output_export = {} self.circuit = circuit @@ -267,7 +267,7 @@ def run_circuit( params.get("expr"), output, width=self.regwidth, - shot_id = self.rng_model.shot_id + shot_id=self.rng_model.shot_id, ) elif params.get("cop_type") == "ExportCVar":