import numpy as np
import matplotlib.pyplot as plt

# Define parameters^M
frequency = 100  # Hz (cycles per second)^M
sampling_rate = 10000  # Samples per second^M
duration = 1  # Seconds^M
time = np.linspace(0, duration, sampling_rate)

# Generate signal^M
signal = np.sin(2 * np.pi * frequency * time)

# Calculate average^M
average = np.mean(signal)

# Print average^M
print("Average of the signal:", average)

# Plot signal^M
plt.plot(time, signal)
plt.xlabel("Time (s)")
plt.ylabel("Signal")
plt.title("Fast-Oscillating Signal (Average: {:.4f})".format(average))
plt.grid(True)
plt.show()

import numpy as np
import matplotlib.pyplot as plt

w_0 = 1e-1
w = np.linspace(0, 1e3, 1000)

func = np.exp(1j*(w_0 - 1*w))

plt.figure(figsize=(10,4))
plt.plot(w, func)
plt.grid()

from qiskit import QuantumCircuit, Aer, execute
from qiskit.visualization import plot_histogram

# Create a Quantum Circuit with 3 qubits
qc = QuantumCircuit(3, 3)

# Create the Bell state
qc.h(1)
qc.cx(1, 2)

# Prepare the state to be teleported
qc.x(0)  # Example: teleporting |1>

# Entangle the qubit to be teleported with the first qubit of the Bell pair
qc.cx(0, 1)
qc.h(0)

# Measure the qubits
qc.measure([0, 1], [0, 1])

# Apply conditional operations based on the measurement results
qc.cx(1, 2)
qc.cz(0, 2)

# Measure the teleported qubit
qc.measure(2, 2)


# Simulate the circuit
simulator = Aer.get_backend('qasm_simulator')
result = execute(qc, backend=simulator, shots=1024).result()

# Get the counts of the measurement results
counts = result.get_counts()

# Plot the results
plot_histogram(counts, title="Standard Quantum Teleportation")


qc.draw(output='mpl')

from qiskit import QuantumCircuit, Aer, execute
from qiskit.visualization import plot_histogram
from qiskit.providers.aer import noise

# Create a Quantum Circuit with 3 qubits
qc_mixed = QuantumCircuit(3, 3)

# Create the Bell state
qc_mixed.h(1)
qc_mixed.cx(1, 2)

# Prepare the state to be teleported
qc_mixed.x(0)  # Example: teleporting |1>

# Entangle the qubit to be teleported with the first qubit of the noisy Bell pair
qc_mixed.cx(0, 1)
qc_mixed.h(0)

# Measure the qubits
qc_mixed.measure([0, 1], [0, 1])

# Apply conditional operations based on the measurement results
qc_mixed.cx(1, 2)
qc_mixed.cz(0, 2)

# Measure the teleported qubit
qc_mixed.measure(2, 2)

# Define a noise model with bit-flip noise
bit_flip_prob = 0.2
bit_flip_noise = noise.pauli_error([('X', bit_flip_prob), ('I', 1 - bit_flip_prob)])

# Create a noise model
noise_model = noise.NoiseModel()
noise_model.add_all_qubit_quantum_error(bit_flip_noise, ['x', 'h'])

# Add single-qubit noise to the circuit to simulate the mixed state
qc_noisy = qc_mixed.copy()
qc_noisy.append(bit_flip_noise.to_instruction(), [1])
qc_noisy.append(bit_flip_noise.to_instruction(), [2])

# Simulate the circuit with noise
simulator = Aer.get_backend('qasm_simulator')
result_mixed = execute(qc_noisy, backend=simulator, shots=1024, noise_model=noise_model).result()

# Get the counts of the measurement results
counts_mixed = result_mixed.get_counts()

# Plot the results
plot_histogram(counts_mixed, title="Teleportation with Mixed State Resource")


import numpy as np
import matplotlib.pyplot as plt

# Define parameters
omega_0 = 1.0  # Resonant frequency of the two-level atom
gamma = 0.1   # Width of the Lorentzian peak for resonant interaction
gamma_off = 0.3  # Width of the off-resonant interaction
omega_off = 1.5  # Center frequency for off-resonant interaction

# Frequency range
omega = np.linspace(0, 2, 1000)

# Lorentzian spectral density function for resonant interaction
def J_resonant(omega, omega_0, gamma):
    return gamma**2 / ((omega - omega_0)**2 + gamma**2)

# Lorentzian spectral density function for off-resonant interaction
def J_off_resonant(omega, omega_off, gamma_off):
    return gamma_off**2 / ((omega - omega_off)**2 + gamma_off**2)

# Total spectral density
def J_total(omega, omega_0, gamma, omega_off, gamma_off):
    return J_resonant(omega, omega_0, gamma) + J_off_resonant(omega, omega_off, gamma_off)

# Compute spectral densities
J_omega_resonant = J_resonant(omega, omega_0, gamma)
J_omega_off_resonant = J_off_resonant(omega, omega_off, gamma_off)
J_omega_total = J_total(omega, omega_0, gamma, omega_off, gamma_off)

# Plot the spectral densities
plt.figure(figsize=(10, 6))
plt.plot(omega, J_omega_resonant, label='Resonant Interaction $J_{\\text{res}}(\\omega)$')
plt.plot(omega, J_omega_off_resonant, label='Off-Resonant Interaction $J_{\\text{off-res}}(\\omega)$')
plt.plot(omega, J_omega_total, label='Total Spectral Density $J_{\\text{total}}(\\omega)$', linestyle='--')
plt.axvline(x=omega_0, color='r', linestyle='--', label='$\\omega_0$ (Resonant Frequency)')
plt.axvline(x=omega_off, color='g', linestyle='--', label='$\\omega_{\\text{off}}$ (Off-Resonant Frequency)')
plt.xlabel('$\\omega$ (Frequency)')
plt.ylabel('$J(\\omega)$ (Spectral Density)')
plt.title('Spectral Density for Two-Level Atom with Resonant and Off-Resonant Interactions')
plt.legend()
plt.grid(True)
plt.show()




