# How to set Q, K and log(pq)

**URL:** https://openfhe.discourse.group/t/how-to-set-q-k-and-log-pq/974
**Category:** Library Questions
**Created:** [December 17, 2023, 11:52pm UTC](https://openfhe.discourse.group/t/how-to-set-q-k-and-log-pq/974 "2023-12-17T23:52:02Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![jomivaan](https://avatars.discourse-cdn.com/v4/letter/j/53a042/32.png) [@jomivaan](https://openfhe.discourse.group/u/jomivaan)
#### Post date: [December 17, 2023, 11:52pm UTC](https://openfhe.discourse.group/t/how-to-set-q-k-and-log-pq/974/1 "2023-12-17T23:52:02Z")

</div>

Hello,  
I am trying to benchmark the NTT implementation of OpenFHE in the CKKS scheme. I am trying to replicate the benchmarks used in this [paper](https://arxiv.org/abs/2212.14191) . They vary N,K,Q and log(pq). K is how many special prime moduli p\_i we have in the Key Switching, I believe.  
I know how to set N, but how can I change the other parameters to match them? I think that in examples they are normally set by the library.  
Thank you

---

<div class="post-metadata">

### Author: ![narger](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/narger/32/420_2.png) [@narger](https://openfhe.discourse.group/u/narger)
#### Post date: [December 18, 2023, 1:58pm UTC](https://openfhe.discourse.group/t/how-to-set-q-k-and-log-pq/974/2 "2023-12-18T13:58:21Z")

</div>

I think \log(qp) refers to the moduli chain. In that case, it depends.

\log(q) is set when defining the circuit depth and the values of \Delta and q\_i's. In particular each level adds a factor q\_i to \log(q).

Consider that, for the basic CKKS setting, the modulus Q at level 0 is Q=q\_1 \cdot q\_2 \cdot ... \cdot q\_l.

Refer to [this thread](https://openfhe.discourse.group/t/openfhe-ckks-chooses-modulus-chain-that-doesnt-guarantee-128-bits-of-security/405) that shows a block of code which prints all the moduli q\_i's

Pay attention that, when using Hybrid Key Switching (HKS), the moduli chain becomes larger (as it becomes \log(q) + log(p)), it is possible to control this increase by changing the value of d\_{num} (set using `parameters.SetNumLargeDigits()`): smaller values (i.e. d\_{num} = 2 or 3), add less bits, but generate larger automorphism keys.

I would wait for an expert confirm, but in general this is the idea.

---

<div class="post-metadata">

### Author: ![jomivaan](https://avatars.discourse-cdn.com/v4/letter/j/53a042/32.png) [@jomivaan](https://openfhe.discourse.group/u/jomivaan)
#### Post date: [December 18, 2023, 3:02pm UTC](https://openfhe.discourse.group/t/how-to-set-q-k-and-log-pq/974/3 "2023-12-18T15:02:11Z")

</div>

Hello, thank you for answering.  
So, log(qp) refers to log(q\_{0} \times p\_{0}) ?  
By setting q\_{0} using `SetfirstModSize` (not sure if this is the correct name, but is something like that), I can control log(q\_{0}).  
I am currently trying to understand HKS at a high level, so I am familiar that the moduli chain gets bigger during the calculations until we perform the ModDown.  
However, I didn’t understand how d\_{num} affects the number of bits in the moduli p\_{i} nor how K is chosen. Sorry to ask, but do you understand how that part works?  
Thank you

---

<div class="post-metadata">

### Author: ![Caesar](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/caesar/32/63_2.png) [@Caesar](https://openfhe.discourse.group/u/Caesar)
#### Post date: [December 19, 2023, 8:14pm UTC](https://openfhe.discourse.group/t/how-to-set-q-k-and-log-pq/974/4 "2023-12-19T20:14:06Z")

</div>

\log{}qp (better to use capital letters for these parameters to avoid confusion) refers to the entire moduli chain in q and p, both are large integers composed of the product of a chain of prime numbers, say q=q\_0 \cdot q\_1 \cdot \cdots q\_{k-1} and p=p\_0 \cdot p\_1 \cdot \cdots p\_{k'-1}.  
To control \log{q}, keep changing the multiplicative depth until you get something close to what you want. Note that changing q might change N automatically by the library unless it is hard set.

I suggest you read this [paper](https://eprint.iacr.org/2021/204) (including the appendices) which describes HKS in detail along with all the parameters you are asking about.
