Skip to content

Commit e669d62

Browse files
authored
Fix cudaq.draw for circuits with exp_pauli (#2678)
* Fix cudaq.draw for circuits with exp_pauli * Bump nvidia-mgpu commit --------- Signed-off-by: Ben Howe <[email protected]>
1 parent 9306347 commit e669d62

File tree

5 files changed

+32
-3
lines changed

5 files changed

+32
-3
lines changed
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
nvidia-mgpu-repo: cuda-quantum/cuquantum-mgpu.git
2-
nvidia-mgpu-commit: 17279375c13290a202ae5c5267f1f571227f1ef4
2+
nvidia-mgpu-commit: de32bf2abae42f118a0da36be0066296d76b0dbc

python/tests/visualization/test_draw.py

+22
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,28 @@ def kernel():
105105
assert expected_str == produced_string
106106

107107

108+
# This test will run on the default simulator. For machines with GPUs, that
109+
# will be a GPU-accelerated simulator, but for machines without GPUs, it
110+
# will run on a CPU simulator.
111+
def test_draw_with_exp_pauli():
112+
@cudaq.kernel
113+
def kernel_exp_pauli():
114+
q = cudaq.qvector(2)
115+
exp_pauli(0.2, q, "ZZ")
116+
117+
118+
expected_str = R"""
119+
120+
q0 : ──●────────────────●──
121+
╭─┴─╮╭──────────╮╭─┴─╮
122+
q1 : ┤ x ├┤ rz(-0.4) ├┤ x ├
123+
╰───╯╰──────────╯╰───╯
124+
"""
125+
expected_str = expected_str[1:]
126+
produced_string = cudaq.draw(kernel_exp_pauli)
127+
assert expected_str == produced_string
128+
129+
108130
def test_draw_hw_target():
109131

110132
@cudaq.kernel

runtime/nvqir/CircuitSimulator.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -386,13 +386,12 @@ class CircuitSimulatorBase : public CircuitSimulator {
386386
/// @brief Reference to the current circuit name.
387387
std::string currentCircuitName = "";
388388

389-
private:
389+
protected:
390390
/// @brief Return true if the simulator is in the tracer mode.
391391
bool isInTracerMode() const {
392392
return executionContext && executionContext->name == "tracer";
393393
}
394394

395-
protected:
396395
/// @brief The current Execution Context (typically this is null,
397396
/// sampling, or spin_op observation.
398397
cudaq::ExecutionContext *executionContext = nullptr;

runtime/nvqir/custatevec/CuStateVecCircuitSimulator.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,10 @@ class CuStateVecCircuitSimulator
456456
void applyExpPauli(double theta, const std::vector<std::size_t> &controlIds,
457457
const std::vector<std::size_t> &qubits,
458458
const cudaq::spin_op &op) override {
459+
if (this->isInTracerMode()) {
460+
nvqir::CircuitSimulator::applyExpPauli(theta, controlIds, qubits, op);
461+
return;
462+
}
459463
flushGateQueue();
460464
cudaq::info(" [cusv decomposing] exp_pauli({}, {})", theta,
461465
op.to_string(false));

runtime/nvqir/cutensornet/simulator_mps_register.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ class SimulatorMPS : public SimulatorTensorNetBase {
112112
const std::vector<std::size_t> &controls,
113113
const std::vector<std::size_t> &qubitIds,
114114
const cudaq::spin_op &op) override {
115+
if (this->isInTracerMode()) {
116+
nvqir::CircuitSimulator::applyExpPauli(theta, controls, qubitIds, op);
117+
return;
118+
}
115119
// Special handling for equivalence of Rxx(theta), Ryy(theta), Rzz(theta)
116120
// expressed as exp_pauli.
117121
// Note: for MPS, the runtime is ~ linear with the number of 2-body gates

0 commit comments

Comments
 (0)