Skip to content

Commit b3cd4b6

Browse files
authored
[Python] Use cudaq.complex() rather than fixed complex type (#3549)
* [Pytest]: use cudaq.complex() rather than hardcoded type Signed-off-by: Thien Nguyen <[email protected]> * Another round of audit Signed-off-by: Thien Nguyen <[email protected]> * Proper precision data reporting in Python Signed-off-by: Thien Nguyen <[email protected]> * Add some more tests and docs Signed-off-by: Thien Nguyen <[email protected]> --------- Signed-off-by: Thien Nguyen <[email protected]>
1 parent 9002924 commit b3cd4b6

21 files changed

+262
-22
lines changed

docs/sphinx/using/backends/hardware/iontrap.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,3 +234,13 @@ Create a project in the Nexus portal. You can find the project ID in the URL of
234234

235235

236236
To see a complete example, take a look at :ref:`Quantinuum examples <quantinuum-examples>`.
237+
238+
.. note::
239+
240+
In local emulation mode (``emulate`` flag set to ``True``), the program will be executed on the :ref:`default simulator <default-simulator>`.
241+
The environment variable ``CUDAQ_DEFAULT_SIMULATOR`` can be used to change the emulation simulator.
242+
243+
For example, the simulation floating point accuracy and/or the simulation capabilities (e.g., maximum number of qubits, supported quantum gates),
244+
depend on the selected simulator.
245+
246+
Any environment variables must be set prior to setting the target or running "`import cudaq`".

docs/sphinx/using/backends/hardware/neutralatom.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,15 @@ To see a complete example, take a look at :ref:`Infleqtion examples <infleqtion-
124124
Moreover, for an end-to-end application workflow example executed on the Infleqtion QPU, take a look at the
125125
:doc:`Anderson Impurity Model ground state solver <../../../applications/python/logical_aim_sqale>` notebook.
126126

127+
.. note::
128+
129+
In local emulation mode (``emulate`` flag set to ``True``), the program will be executed on the :ref:`default simulator <default-simulator>`.
130+
The environment variable ``CUDAQ_DEFAULT_SIMULATOR`` can be used to change the emulation simulator.
131+
132+
For example, the simulation floating point accuracy and/or the simulation capabilities (e.g., maximum number of qubits, supported quantum gates),
133+
depend on the selected simulator.
134+
135+
Any environment variables must be set prior to setting the target or running "`import cudaq`".
127136

128137
Pasqal
129138
++++++++++++++++

docs/sphinx/using/backends/hardware/superconducting.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,3 +534,13 @@ Submitting
534534

535535
To see a complete example of using Quantum Circuits' backends, please take a look at the
536536
:ref:`Quantum Circuits examples <quantum-circuits-examples>`.
537+
538+
.. note::
539+
540+
In local emulation mode (``emulate`` flag set to ``True``), the program will be executed on the :ref:`default simulator <default-simulator>`.
541+
The environment variable ``CUDAQ_DEFAULT_SIMULATOR`` can be used to change the emulation simulator.
542+
543+
For example, the simulation floating point accuracy and/or the simulation capabilities (e.g., maximum number of qubits, supported quantum gates),
544+
depend on the selected simulator.
545+
546+
Any environment variables must be set prior to setting the target or running "`import cudaq`".

python/tests/backends/test_IQM.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ def kernel(state: cudaq.State):
208208
qubits = cudaq.qvector(state)
209209

210210
state = cudaq.State.from_data(
211-
np.array([1. / np.sqrt(2.), 1. / np.sqrt(2.), 0., 0.], dtype=complex))
211+
np.array([1. / np.sqrt(2.), 1. / np.sqrt(2.), 0., 0.],
212+
dtype=cudaq.complex()))
212213

213214
counts = cudaq.sample(kernel, state)
214215
print(counts)
@@ -231,7 +232,8 @@ def test_IQM_state_synthesis_from_simulator_builder():
231232
qubits = kernel.qalloc(state)
232233

233234
state = cudaq.State.from_data(
234-
np.array([1. / np.sqrt(2.), 1. / np.sqrt(2.), 0., 0.], dtype=complex))
235+
np.array([1. / np.sqrt(2.), 1. / np.sqrt(2.), 0., 0.],
236+
dtype=cudaq.complex()))
235237

236238
counts = cudaq.sample(kernel, state)
237239
assert "00" in counts

python/tests/backends/test_Infleqtion.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ def kernel(state: cudaq.State):
161161
mz(qubits)
162162

163163
state = cudaq.State.from_data(
164-
np.array([1. / np.sqrt(2.), 1. / np.sqrt(2.), 0., 0.], dtype=complex))
164+
np.array([1. / np.sqrt(2.), 1. / np.sqrt(2.), 0., 0.],
165+
dtype=cudaq.complex()))
165166

166167
counts = cudaq.sample(kernel, state)
167168
assert "00" in counts

python/tests/backends/test_IonQ.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ def kernel(state: cudaq.State):
196196
qubits = cudaq.qvector(state)
197197

198198
state = cudaq.State.from_data(
199-
np.array([1. / np.sqrt(2.), 1. / np.sqrt(2.), 0., 0.], dtype=complex))
199+
np.array([1. / np.sqrt(2.), 1. / np.sqrt(2.), 0., 0.],
200+
dtype=cudaq.complex()))
200201

201202
counts = cudaq.sample(kernel, state)
202203
assert "00" in counts
@@ -216,7 +217,8 @@ def test_ionq_state_synthesis_from_simulator_builder():
216217
qubits = kernel.qalloc(state)
217218

218219
state = cudaq.State.from_data(
219-
np.array([1. / np.sqrt(2.), 1. / np.sqrt(2.), 0., 0.], dtype=complex))
220+
np.array([1. / np.sqrt(2.), 1. / np.sqrt(2.), 0., 0.],
221+
dtype=cudaq.complex()))
220222

221223
counts = cudaq.sample(kernel, state)
222224
assert "00" in counts

python/tests/backends/test_Ionq_LocalEmulation_kernel.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ def kernel(state: cudaq.State):
101101
qubits = cudaq.qvector(state)
102102

103103
state = cudaq.State.from_data(
104-
np.array([1. / np.sqrt(2.), 1. / np.sqrt(2.), 0., 0.], dtype=complex))
104+
np.array([1. / np.sqrt(2.), 1. / np.sqrt(2.), 0., 0.],
105+
dtype=cudaq.complex()))
105106

106107
counts = cudaq.sample(kernel, state)
107108
assert "00" in counts

python/tests/backends/test_OQC.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ def kernel(state: cudaq.State):
197197
qubits = cudaq.qvector(state)
198198

199199
state = cudaq.State.from_data(
200-
np.array([1. / np.sqrt(2.), 1. / np.sqrt(2.), 0., 0.], dtype=complex))
200+
np.array([1. / np.sqrt(2.), 1. / np.sqrt(2.), 0., 0.],
201+
dtype=cudaq.complex()))
201202

202203
counts = cudaq.sample(kernel, state)
203204
assert "00" in counts
@@ -217,7 +218,8 @@ def test_OQC_state_synthesis_from_simulator_builder():
217218
qubits = kernel.qalloc(state)
218219

219220
state = cudaq.State.from_data(
220-
np.array([1. / np.sqrt(2.), 1. / np.sqrt(2.), 0., 0.], dtype=complex))
221+
np.array([1. / np.sqrt(2.), 1. / np.sqrt(2.), 0., 0.],
222+
dtype=cudaq.complex()))
221223

222224
counts = cudaq.sample(kernel, state)
223225
assert "00" in counts

python/tests/backends/test_QCI.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ def kernel(state: cudaq.State):
175175
mz(qubits)
176176

177177
state = cudaq.State.from_data(
178-
np.array([1. / np.sqrt(2.), 1. / np.sqrt(2.), 0., 0.], dtype=complex))
178+
np.array([1. / np.sqrt(2.), 1. / np.sqrt(2.), 0., 0.],
179+
dtype=cudaq.complex()))
179180

180181
counts = cudaq.sample(kernel, state)
181182
assert "00" in counts

python/tests/backends/test_Quantinuum_LocalEmulation_builder.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ def test_quantinuum_state_synthesis_from_simulator():
142142
qubits = kernel.qalloc(state)
143143

144144
state = cudaq.State.from_data(
145-
np.array([1. / np.sqrt(2.), 1. / np.sqrt(2.), 0., 0.], dtype=complex))
145+
np.array([1. / np.sqrt(2.), 1. / np.sqrt(2.), 0., 0.],
146+
dtype=cudaq.complex()))
146147

147148
counts = cudaq.sample(kernel, state)
148149
assert "00" in counts
@@ -209,7 +210,7 @@ def test_capture_array():
209210

210211

211212
def test_capture_state():
212-
s = cudaq.State.from_data(np.array([1., 0], dtype=np.complex128))
213+
s = cudaq.State.from_data(np.array([1., 0], dtype=cudaq.complex()))
213214

214215
kernel = cudaq.make_kernel()
215216
q = kernel.qalloc(s)

0 commit comments

Comments
 (0)