Skip to content

Commit ca1f7fa

Browse files
add analogcircuit example
1 parent 3113996 commit ca1f7fa

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

examples/analog_rydberg.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
"""
2+
Analog circuit simulation for Rydberg array
3+
"""
4+
5+
import numpy as np
6+
import tensorcircuit as tc
7+
8+
K = tc.set_backend("jax")
9+
tc.set_dtype("complex128")
10+
11+
# Define simulation parameters
12+
# a compatible set of units: mus, mum, MHz
13+
nqubits = 12
14+
omega = 2.0 * np.pi
15+
delta = 0.0
16+
c6 = 8e8
17+
evolution_time = 2.0
18+
19+
# Define the 1D lattice
20+
chain = tc.templates.lattice.ChainLattice([nqubits], lattice_constant=10, pbc=False)
21+
22+
# Instantiate the AnalogCircuit
23+
ac = tc.AnalogCircuit(nqubits)
24+
25+
# 1. Create the sparsely excited state
26+
ac.x([i for i in range(nqubits) if i % 4 == 0])
27+
28+
rydberg_hmatrix = tc.templates.hamiltonians.rydberg_hamiltonian(
29+
chain, omega=omega, delta=delta, c6=c6
30+
)
31+
32+
33+
# 2. Define the time-dependent Rydberg Hamiltonian
34+
def rydberg_hamiltonian_func(t):
35+
# In this example, the Hamiltonian is time-independent, but it could be a function of t
36+
return rydberg_hmatrix
37+
38+
39+
# 3. Add the analog evolution block
40+
ac.add_analog_block(rydberg_hamiltonian_func, time=evolution_time)
41+
42+
# 4. apply some digital gates if needed, say for random measurements
43+
44+
# for i in range(nqubits):
45+
# j = np.random.choice(3)
46+
# if j == 1:
47+
# ac.h(i)
48+
# elif j == 2:
49+
# ac.rx(i, theta=-np.pi/4)
50+
51+
# 5. Sample from the final state in the computational basis
52+
sample = ac.sample(batch=1024, allow_state=True, format="count_dict_bin")
53+
print("\nSampled bitstrings:\n", sample)

tests/test_analogcircuit.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ def hamiltonian(t):
146146

147147
ac.add_analog_block(hamiltonian, [1.0, 2.3])
148148
# jaxodeint somehow incompatible with h0 outside hamiltonian function
149+
# https://github.com/jax-ml/jax/issues/31792
149150
ac.cx(1, 0)
150151
return tc.backend.real(ac.expectation_ps(z=[1]))
151152

0 commit comments

Comments
 (0)