From 1de4acaa9f256314092180f896e77f0cac3b433c Mon Sep 17 00:00:00 2001 From: Chanandellar Bong <75779966+AbdullahKazi500@users.noreply.github.com> Date: Fri, 7 Jun 2024 21:56:20 +0530 Subject: [PATCH] Create quaqsim.architectures.resonator.py --- quaqsim/quaqsim.architectures.resonator.py | 225 +++++++++++++++++++++ 1 file changed, 225 insertions(+) create mode 100644 quaqsim/quaqsim.architectures.resonator.py diff --git a/quaqsim/quaqsim.architectures.resonator.py b/quaqsim/quaqsim.architectures.resonator.py new file mode 100644 index 0000000..7c442a7 --- /dev/null +++ b/quaqsim/quaqsim.architectures.resonator.py @@ -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