Skip to content

oscillator

Oscillator gates.

CD(N, beta, ts=None)

Conditional displacement gate.

Parameters:

Name Type Description Default
N

Hilbert space dimension.

required
beta

Conditional displacement amplitude.

required
ts

Optional time sequence for hamiltonian simulation.

None

Returns:

Type Description

Conditional displacement gate.

Source code in jaxquantum/circuits/library/oscillator.py
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
def CD(N, beta, ts=None):
    """Conditional displacement gate.

    Args:
        N: Hilbert space dimension.
        beta: Conditional displacement amplitude.
        ts: Optional time sequence for hamiltonian simulation.

    Returns:
        Conditional displacement gate.
    """
    gen_Ht = None
    if ts is not None:
        g = basis(2, 0)
        e = basis(2, 1)
        gg = g @ g.dag()
        ee = e @ e.dag()
        delta_t = ts[-1] - ts[0]
        amp = 1j * beta / delta_t / 2
        a = destroy(N)
        gen_Ht = lambda params: lambda t: (
            gg
            ^ (jnp.conj(amp) * a + amp * a.dag()) + ee
            ^ (jnp.conj(-amp) * a + (-amp) * a.dag())
        )

    return Gate.create(
        [2, N],
        name="CD",
        params={"beta": beta},
        gen_U=lambda params: _conditional_displacement(N, params["beta"]),
        gen_Ht=gen_Ht,
        ts=ts,
        num_modes=2,
    )

CR(N, theta)

Conditional rotation gate.

Parameters:

Name Type Description Default
N

Hilbert space dimension.

required
theta

Conditional rotation angle.

required

Returns:

Type Description

Conditional rotation gate.

Source code in jaxquantum/circuits/library/oscillator.py
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
def CR(N, theta):
    """Conditional rotation gate.

    Args:
        N: Hilbert space dimension.
        theta: Conditional rotation angle.

    Returns:
        Conditional rotation gate.
    """
    g = basis(2, 0)
    e = basis(2, 1)

    gg = g @ g.dag()
    ee = e @ e.dag()


    return Gate.create(
        [2, N],
        name="CR",
        params={"theta": theta},
        gen_U=lambda params: (gg ^ (-1.j*theta/2*create(N)@destroy(N)).expm())
        + (ee ^ (1.j*theta/2*create(N)@destroy(N)).expm()),
        num_modes=2,
    )

D(N, alpha, ts=None, c_ops=None)

Displacement gate.

Parameters:

Name Type Description Default
N

Hilbert space dimension.

required
alpha

Displacement amplitude.

required
ts

Optional time array for hamiltonian simulation.

None
c_ops

Optional collapse operators.

None

Returns:

Type Description

Displacement gate.

Source code in jaxquantum/circuits/library/oscillator.py
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
def D(N, alpha, ts=None, c_ops=None):
    """Displacement gate.

    Args:
        N: Hilbert space dimension.
        alpha: Displacement amplitude.
        ts: Optional time array for hamiltonian simulation.
        c_ops: Optional collapse operators.

    Returns:
        Displacement gate.
    """
    gen_Ht = None
    if ts is not None:
        delta_t = ts[-1] - ts[0]
        amp = 1j * alpha / delta_t
        a = destroy(N)
        gen_Ht = lambda params: (lambda t: jnp.conj(amp) * a + amp * a.dag())

    return Gate.create(
        N,
        name="D",
        params={"alpha": alpha},
        gen_U=lambda params: displace(N, params["alpha"]),
        gen_Ht=gen_Ht,
        ts=ts,
        gen_c_ops=lambda params: Qarray.from_list([]) if c_ops is None else c_ops,
        num_modes=1,
    )

ECD(N, beta, ts=None)

Echoed conditional displacement gate.

Parameters:

Name Type Description Default
N

Hilbert space dimension.

required
beta

Conditional displacement amplitude.

required
ts

Optional time sequence for hamiltonian simulation.

None

Returns:

Type Description

Echoed conditional displacement gate.

Source code in jaxquantum/circuits/library/oscillator.py
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
def ECD(N, beta, ts=None):
    """Echoed conditional displacement gate.

    Args:
        N: Hilbert space dimension.
        beta: Conditional displacement amplitude.
        ts: Optional time sequence for hamiltonian simulation.

    Returns:
        Echoed conditional displacement gate.
    """
    return Gate.create(
        [2, N],
        name="ECD",
        params={"beta": beta},
        gen_U=lambda params: _conditional_displacement(
            N,
            params["beta"],
            echoed=True,
        ),
        gen_Ht=None,
        ts=ts,
        num_modes=2,
    )

diag_expm(diag_matrix)

Computes expm of a diagonal matrix efficiently (O(N) instead of O(N^3)).

Source code in jaxquantum/circuits/library/oscillator.py
16
17
18
19
def diag_expm(diag_matrix):
    """Computes expm of a diagonal matrix efficiently (O(N) instead of O(N^3))."""
    # Extract diagonal, exponentiate elements, put back on diagonal
    return jnp.diag(jnp.exp(jnp.diagonal(diag_matrix)))