I will use $\tau$ instead of $z$, and assume that we have the nome-convention:
$$
q = q(\tau)=e^{2\pi i\; \tau}\ .
$$
There is in sage already a (related) function for the expansion of the mentioned $\theta$-function,

```
sage: f = (1 + theta_qexp(150)) / 2
sage: f
1 + q + q^4 + q^9 + q^16 + q^25 + q^36 + q^49 + q^64 + q^81 + q^100 + q^121 + q^144 + O(q^150)
```

(The implemented `theta_qexp`

corresponds to the "same" sum where $n$ runs in $\Bbb Z$.)

Now we can take our own power series ring in (an other) variable $q$, or use this one above.
I will use "mine", so that a precision is also in there.

The $g$ is quickly computed, using
$$
\eta(\tau)=q^{1/24}\prod_{n\ge 1}(1-q^n)\ ,
$$
We have, using some higher precision:

```
PREC = 500
R.<q> = PowerSeriesRing(QQ)
f = sum([q^(n^2) for n in range(floor(sqrt(PREC)))]) + O(q^PREC)
g = q * prod([ (1 - q^(5*n) + O(q^PREC))^5/(1 - q^n + O(q^PREC)) for n in [1..PREC] ])
h = g^2 + f^8
print(h + O(q^20))
```

The last print shows some first few terms, i see no "good" pattern...

```
1 + 8*q + 29*q^2 + 58*q^3 + 83*q^4 + 122*q^5 + 216*q^6 + 314*q^7 + 354*q^8 + 404*q^9 + 617*q^10 + 836*q^11 + 912*q^12 + 956*q^13 + 1332*q^14 + 1726*q^15 + 1851*q^16 + 1776*q^17 + 2309*q^18 + 2984*q^19 + O(q^20)
```

Presumably there is a relationship between

`q`

and`z`

?Also, what is $g^2(z)$? Do you mean $g(z)^2$ or is it the second compositional power?

$g^2(z)$ means $g(z)^2$ and $q = e^{2\pi iz}$