-
Notifications
You must be signed in to change notification settings - Fork 349
Expand file tree
/
Copy pathtrajectory_batching.py
More file actions
46 lines (37 loc) · 1.58 KB
/
trajectory_batching.py
File metadata and controls
46 lines (37 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# ============================================================================ #
# Copyright (c) 2022 - 2024 NVIDIA Corporation & Affiliates. #
# All rights reserved. #
# #
# This source code and the accompanying materials are made available under #
# the terms of the Apache License 2.0 which accompanies this distribution. #
# ============================================================================ #
#[Begin Docs]
import time
import cudaq
# Use the `nvidia` target
cudaq.set_target("nvidia")
# Let's define a simple kernel that we will add noise to.
qubit_count = 10
@cudaq.kernel
def kernel(qubit_count: int):
qvector = cudaq.qvector(qubit_count)
x(qvector)
mz(qvector)
# Add a simple bit-flip noise channel to X gate
error_probability = 0.01
bit_flip = cudaq.BitFlipChannel(error_probability)
# Add noise channels to our noise model.
noise_model = cudaq.NoiseModel()
# Apply the bit-flip channel to any X-gate on any qubits
noise_model.add_all_qubit_channel("x", bit_flip)
ideal_counts = cudaq.sample(kernel, qubit_count, shots_count=1000)
start = time.time()
# Due to the impact of noise, our measurements will no longer be uniformly
# in the |1...1> state.
noisy_counts = cudaq.sample(kernel,
qubit_count,
noise_model=noise_model,
shots_count=1000)
end = time.time()
noisy_counts.dump()
print(f"Simulation elapsed time: {(end - start) * 1000} ms")