-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathnoisy_circuit_simple_api.py
More file actions
66 lines (53 loc) · 1.67 KB
/
noisy_circuit_simple_api.py
File metadata and controls
66 lines (53 loc) · 1.67 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"""Simplified Noise API Demo.
This example demonstrates the new user-friendly noise API using .with_noise()
"""
import tyxonq as tq
print("=" * 60)
print("Simplified Noise API Demo")
print("=" * 60)
# Set backend
tq.set_backend("numpy")
# Create Bell state circuit
c = tq.Circuit(2)
c.h(0).cx(0, 1)
print("\n1. Original API (verbose):")
print("-" * 60)
result_old = c.device(
provider="simulator",
device="density_matrix",
use_noise=True,
noise={"type": "depolarizing", "p": 0.05}
).run(shots=1024)
print(f"Result: {result_old[0]['result']}")
print("\n2. New with_noise() API (simplified):")
print("-" * 60)
c2 = tq.Circuit(2)
c2.h(0).cx(0, 1)
result_new = c2.with_noise("depolarizing", p=0.05).run(shots=1024)
print(f"Result: {result_new[0]['result']}")
print("\n3. Different noise types:")
print("-" * 60)
# Amplitude damping
c3 = tq.Circuit(2)
c3.h(0).cx(0, 1)
result = c3.with_noise("amplitude_damping", gamma=0.1).run(shots=1024)
print(f"Amplitude damping: {result[0]['result']}")
# Phase damping (using 'l' instead of 'lambda' to avoid Python keyword)
c4 = tq.Circuit(2)
c4.h(0).cx(0, 1)
result = c4.with_noise("phase_damping", l=0.1).run(shots=1024)
print(f"Phase damping: {result[0]['result']}")
# Pauli channel
c5 = tq.Circuit(2)
c5.h(0).cx(0, 1)
result = c5.with_noise("pauli", px=0.01, py=0.01, pz=0.05).run(shots=1024)
print(f"Pauli channel: {result[0]['result']}")
print("\n4. Chaining with other methods:")
print("-" * 60)
c6 = tq.Circuit(2)
c6.h(0).cx(0, 1)
result = c6.with_noise("depolarizing", p=0.05).device(shots=2048).run()
print(f"Chained result: {result[0]['result']}")
print("\n" + "=" * 60)
print("✓ Simplified noise API works perfectly!")
print("=" * 60)