Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

quaqsim.architectures.resonator.py #11

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
225 changes: 225 additions & 0 deletions quaqsim/quaqsim.architectures.resonator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
class Transmon:
"""
Class representing a transmon qubit.

Attributes:
settings (TransmonSettings): Settings for the transmon.
resonant_frequency (float): Resonant frequency of the transmon.
rabi_frequency (float): Rabi frequency of the transmon.
anharmonicity (float): Anharmonicity of the transmon.
resonator (Resonator): Resonator object representing the coupled resonator, if any.
"""

def __init__(self, settings, resonator=None):
"""
Initialize the Transmon object.

Args:
settings (TransmonSettings): Settings for the transmon.
resonator (Resonator, optional): Resonator object representing the coupled resonator. Defaults to None.
"""
self.settings = settings
self.resonant_frequency = settings.resonant_frequency
self.rabi_frequency = settings.rabi_frequency
self.anharmonicity = settings.anharmonicity
self.resonator = resonator

def system_hamiltonian(self, N) -> np.ndarray:
"""
Calculate the system Hamiltonian matrix.

Args:
N (np.ndarray): Number basis for the Hilbert space.

Returns:
np.ndarray: System Hamiltonian matrix.
"""
# Initializing the system Hamiltonian matrix without the resonator
hamiltonian = (
2 * np.pi * self.resonant_frequency * N
+ np.pi * self.anharmonicity * N * (N - np.identity(N.shape[0]))
)

# in
if self.resonator:
hamiltonian += self.resonator.system_hamiltonian(N)

return hamiltonian
class Resonator:
"""
Class representing a resonator coupled to a transmon qubit.

Attributes:
resonant_frequency (float): Resonant frequency of the resonator.
"""

def __init__(self, resonant_frequency):
"""
Initialize the Resonator object.

Args:
resonant_frequency (float): Resonant frequency of the resonator.
"""
self.resonant_frequency = resonant_frequency

def system_hamiltonian(self, N) -> np.ndarray:
"""
Calculate the system Hamiltonian matrix for the resonator.

Args:
N (np.ndarray): Number basis for the Hilbert space.

Returns:
np.ndarray: System Hamiltonian matrix.
"""
# Implementing the Hamiltonian matrix for the resonator
# Example implementation
return 2 * np.pi * self.resonant_frequency * N

def photon_count(self, state_vector) -> float:
"""
Calculate the photon count in the resonator.

Args:
state_vector (np.ndarray): State vector representing the quantum state.

Returns:
float: Photon count in the resonator.
"""
# Calculating the photon count in the resonator as a proxy for the transmon state
# Example implementation
return np.abs(np.dot(np.conj(state_vector), state_vector))
from qiskit.pulse import ShiftFrequency

class Resonator:
"""
Class representing a resonator coupled to a transmon qubit.

Attributes:
resonant_frequency (float): Resonant frequency of the resonator.
"""

def __init__(self, resonant_frequency):
"""
Initialize the Resonator object.

Args:
resonant_frequency (float): Resonant frequency of the resonator.
"""
self.resonant_frequency = resonant_frequency

def system_hamiltonian(self, N) -> np.ndarray:
"""
Calculate the system Hamiltonian matrix for the resonator.

Args:
N (np.ndarray): Number basis for the Hilbert space.

Returns:
np.ndarray: System Hamiltonian matrix.
"""
# Implementing the Hamiltonian matrix for the resonator
# Example implementation
return 2 * np.pi * self.resonant_frequency * N

def update_frequency(self, new_frequency, qmm):
"""
Update the frequency of the resonator.

Args:
new_frequency (float): New resonant frequency of the resonator.
qmm (QuantumMachinesManager): Quantum Machines Manager for adding the shift frequency instruction.
"""
# Shift the frequency of the resonator
shift_frequency = ShiftFrequency(new_frequency - self.resonant_frequency, channel="resonator")
qmm.add_instruction(shift_frequency)
self.resonant_frequency = new_frequency

def photon_count(self, state_vector) -> float:
"""
Calculate the photon count in the resonator.

Args:
state_vector (np.ndarray): State vector representing the quantum state.

Returns:
float: Photon count in the resonator.
"""
# Calculating the photon count in the resonator as a proxy for the transmon state
# Example implementation
return np.abs(np.dot(np.conj(state_vector), state_vector))
class Resonator:
"""
Class representing a resonator coupled to a transmon qubit.

Attributes:
resonant_frequency (float): Resonant frequency of the resonator.
"""

def __init__(self, resonant_frequency):
"""
Initialize the Resonator object.

Args:
resonant_frequency (float): Resonant frequency of the resonator.
"""
self.resonant_frequency = resonant_frequency

def system_hamiltonian(self, N) -> np.ndarray:
"""
Calculate the system Hamiltonian matrix for the resonator.

Args:
N (np.ndarray): Number basis for the Hilbert space.

Returns:
np.ndarray: System Hamiltonian matrix.
"""
# Implementing the Hamiltonian matrix for the resonator
# Example implementation
return 2 * np.pi * self.resonant_frequency * N

def photon_count(self, state_vector) -> float:
"""
Calculate the photon count in the resonator.

Args:
state_vector (np.ndarray): State vector representing the quantum state.

Returns:
float: Photon count in the resonator.
"""
# Calculating the photon count in the resonator as a proxy for the transmon state
# Example implementation
return np.abs(np.dot(np.conj(state_vector), state_vector))
with program() as resonator_spec_2D:
# Define variables and streams
with for_(n, 0, n < n_avg, n + 1):
with for_(*from_array(df, dfs)):
# Update frequency
update_frequency("resonator", df + resonator_IF)
with for_each_(a, amplitudes):
# Measure the resonator
measure(
"readout" * amp(a),
"resonator",
None,
dual_demod.full("cos", "out1", "sin", "out2", I),
dual_demod.full("minus_sin", "out1", "cos", "out2", Q),
)
# Wait for depletion
wait(depletion_time * u.ns, "resonator")
# Save quadratures
save(I, I_st)
save(Q, Q_st)
# Save iteration
save(n, n_st)

with stream_processing():
# Cast data into 2D matrix and average
I_st.buffer(len(amplitudes)).buffer(len(dfs)).average().save("I")
Q_st.buffer(len(amplitudes)).buffer(len(dfs)).average().save("Q")
n_st.save("iteration")

# Plotting results
# plot code to observe the variation in reflected signal amplitude