Skip to content

Commit

Permalink
added support for rar system
Browse files Browse the repository at this point in the history
  • Loading branch information
Phionx committed Jul 21, 2024
1 parent fe91023 commit 3534ea2
Show file tree
Hide file tree
Showing 6 changed files with 599 additions and 14 deletions.
31 changes: 18 additions & 13 deletions qcsys/devices/ats.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ def common_ops(self):
def phi_zpf(self):
"""Return Phase ZPF."""
return (2*self.params["Ec"]/self.params["El"])**(.25)

def n_zpf(self):
"""Return Charge ZPF."""
return (self.params["El"]/(32*self.params["Ec"]))**(.25)

def get_linear_ω(self):
"""Get frequency of linear terms."""
Expand All @@ -39,31 +43,32 @@ def get_H_linear(self):
w = self.get_linear_ω()
return w*(self.linear_ops["a_dag"]@self.linear_ops["a"] + 0.5 * self.linear_ops["id"])

def get_H_full(self):
"""Return full H in linear basis."""
# raise NotImplemented("This has not yet been implemented.")

# extra ATS terms
def get_H_nonlinear(self, phi_op, id_op):
"""Return nonlinear terms in H."""

Ej = self.params["Ej"]
dEj = self.params["dEj"]
Ej2 = self.params["Ej2"]

phi_delta_ext_op = self.params["phi_delta_ext"] * id_op
H_nl = - 2 * Ej * jqt.cosm(phi_op + 2 * jnp.pi * phi_delta_ext_op) * jnp.cos(2 * jnp.pi * self.params["phi_sum_ext"])
H_nl += 2 * dEj * jqt.sinm(phi_op + 2 * jnp.pi * phi_delta_ext_op) * jnp.sin(2 * jnp.pi * self.params["phi_sum_ext"])
H_nl += 2 * Ej2 * jqt.cosm(2*phi_op + 2 * 2 * jnp.pi * phi_delta_ext_op) * jnp.cos(2 * 2 * jnp.pi * self.params["phi_sum_ext"])
return H_nl

def get_H_full(self):
"""Return full H in linear basis."""
id_op = self.linear_ops["id"]
phi_b = self.linear_ops["phi"]
id = self.linear_ops["id"]

phi_delta_ext_op = self.params["phi_delta_ext"] * id

H_nl = - 2 * Ej * jqt.cosm(phi_b + 2 * jnp.pi * phi_delta_ext_op) * jnp.cos(2 * jnp.pi * self.params["phi_sum_ext"])
H_nl += 2 * dEj * jqt.sinm(phi_b + 2 * jnp.pi * phi_delta_ext_op) * jnp.sin(2 * jnp.pi * self.params["phi_sum_ext"])
H_nl += 2 * Ej2 * jqt.cosm(2*phi_b + 2 * 2 * jnp.pi * phi_delta_ext_op) * jnp.cos(2 * 2 * jnp.pi * self.params["phi_sum_ext"])

H_nl = self.get_H_nonlinear(phi_b, id_op)
H = self.get_H_linear() + H_nl
return H

def potential(self, phi):
"""Return potential energy for a given phi."""

phi_delta_ext = self.params["phi_delta_ext"]
phi_delta_ext = self.params["phi_delta"]
phi_sum_ext = self.params["phi_sum_ext"]

V = 0.5 * self.params["El"] * (2 * jnp.pi * phi) ** 2
Expand Down
5 changes: 5 additions & 0 deletions qcsys/devices/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ def create(
couplings: Optional[List[Array]] = None,
params: Optional[Dict[str, Any]] = None,
):
labels = [device.label for device in devices]
unique_labels = set(labels)
if len(labels) != len(unique_labels):
raise ValueError("Devices must have unique labels.")

Ns = tuple([device.N for device in devices])
couplings = couplings if couplings is not None else []
params = params if params is not None else {}
Expand Down
2 changes: 1 addition & 1 deletion tutorials/1-demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"source": [
"from jax import jit, grad\n",
"import qcsys as qs\n",
"import jax.numpy as jnp\n"
"import jax.numpy as jnp"
]
},
{
Expand Down
229 changes: 229 additions & 0 deletions tutorials/6-normal-mode-approach-to-fluxonium.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"%load_ext autoreload\n",
"%autoreload 2"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"from jax import jit, grad\n",
"import qcsys as qs\n",
"import jax.numpy as jnp\n",
"import jaxquantum as jqt"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"def calculate_chi_diagonalize():\n",
" _, Ec_a, El_a = qs.calculate_lambda_over_four_resonator_zpf(5, 50)\n",
"\n",
" resonator = qs.Resonator.create(\n",
" 10,\n",
" {\"Ec\": Ec_a, \"El\": El_a},\n",
" N_pre_diag=10,\n",
" )\n",
"\n",
" Ec_q = 1\n",
" El_q = 0.5\n",
" Ej_q = 8\n",
"\n",
" qubit = qs.Fluxonium.create(\n",
" 25,\n",
" {\"Ec\": Ec_q, \"El\": El_q, \"Ej\": Ej_q, \"phi_ext\": 0.47},\n",
" use_linear=False,\n",
" N_pre_diag=100,\n",
" )\n",
"\n",
" g_rq = 0.3\n",
"\n",
" devices = [resonator, qubit]\n",
" r_indx = 0\n",
" q_indx = 1\n",
" Ns = [device.N for device in devices]\n",
"\n",
" a0 = qs.promote(resonator.ops[\"a\"], r_indx, Ns)\n",
" a0_dag = qs.promote(resonator.ops[\"a_dag\"], r_indx, Ns)\n",
"\n",
" q0 = qs.promote(qubit.ops[\"a\"], q_indx, Ns)\n",
" q0_dag = qs.promote(qubit.ops[\"a_dag\"], q_indx, Ns)\n",
"\n",
" couplings = []\n",
" couplings.append(-g_rq * (a0 - a0_dag) @ (q0 - q0_dag))\n",
"\n",
" system = qs.System.create(devices, couplings=couplings)\n",
" system.params[\"g_rq\"] = g_rq\n",
"\n",
" Es, kets = system.calculate_eig()\n",
"\n",
" # chi ----\n",
" χ_e = Es[1:, 1] - Es[:-1, 1]\n",
" χ_g = Es[1:, 0] - Es[:-1, 0]\n",
" χ = χ_e - χ_g\n",
"\n",
" return χ"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Array([-0.00399307, -0.00369734, -0.0191641 , 0.13341733, -0.19415304,\n",
" -0.00187664, -1.06201788, 1.10409898, -0.49863942], dtype=float64)"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"calculate_chi_diagonalize()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Normal Mode Approach"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"# Normal Mode Estimate\n",
"\n",
"def calculate_chi_normal_modes():\n",
" _, Ec_a, El_a = qs.calculate_lambda_over_four_resonator_zpf(5, 50)\n",
"\n",
" resonator = qs.Resonator.create(\n",
" 10,\n",
" {\"Ec\": Ec_a, \"El\": El_a},\n",
" N_pre_diag=10,\n",
" )\n",
"\n",
" Ec_q = 1\n",
" El_q = 0.5\n",
" Ej_q = 8\n",
"\n",
" qubit = qs.Fluxonium.create(\n",
" 25,\n",
" {\"Ec\": Ec_q, \"El\": El_q, \"Ej\": Ej_q, \"phi_ext\": 0.47},\n",
" use_linear=True,\n",
" N_pre_diag=100,\n",
" )\n",
"\n",
" g_rq = 0.3\n",
"\n",
" devices = [resonator, qubit]\n",
" r_indx = 0\n",
" q_indx = 1\n",
" Ns = [device.N for device in devices]\n",
"\n",
" a0 = qs.promote(resonator.ops[\"a\"], r_indx, Ns)\n",
" a0_dag = qs.promote(resonator.ops[\"a_dag\"], r_indx, Ns)\n",
"\n",
" q0 = qs.promote(qubit.ops[\"a\"], q_indx, Ns)\n",
" q0_dag = qs.promote(qubit.ops[\"a_dag\"], q_indx, Ns)\n",
"\n",
" couplings = []\n",
" couplings.append(-g_rq * (a0 - a0_dag) @ (q0 - q0_dag))\n",
"\n",
" linear_system = qs.System.create(devices, couplings=couplings)\n",
" linear_system.params[\"g_rq\"] = g_rq\n",
"\n",
" Es, kets = linear_system.calculate_eig()\n",
"\n",
" # participations\n",
"\n",
" vac = kets[0, 0]\n",
" \n",
" e = {}\n",
" e[linear_system.devices[0].label] = kets[1, 0]\n",
" e[linear_system.devices[1].label] = kets[0, 1]\n",
" e.keys()\n",
"\n",
" \"\"\"extract participations\"\"\"\n",
" ϕ = {device.label: {} for device in linear_system.devices}\n",
"\n",
" for j, d1 in enumerate(linear_system.devices):\n",
" phi_0 = linear_system.promote(d1.ops[\"phi\"], j).data\n",
" for d2 in linear_system.devices:\n",
" ϕ[d1.label][d2.label] = jqt.dag_data(e[d2.label]) @ phi_0 @ vac\n",
"\n",
" theta_a = ϕ[\"Fluxonium0\"][\"Resonator0\"]\n",
"\n",
"\n",
" return theta_a"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Array(0.19994616+0.j, dtype=complex128)"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"calculate_chi_normal_modes()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "jax-framework",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.18"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
89 changes: 89 additions & 0 deletions tutorials/ats-coupler/0-resonator-ats-resonator.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"%load_ext autoreload\n",
"%autoreload 2"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"from jax import jit, grad\n",
"import qcsys as qs\n",
"import jax.numpy as jnp\n",
"from rar_helpers import *"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"import jaxquantum as jqt"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"# system, ϕ0, metrics0, system0 = get_system_normal_rar({})\n",
"ϕ0, metrics0, system0 = get_metrics_linear_rar({})"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'g_ex': Array(-0.00212182+0.j, dtype=complex128),\n",
" 'ω_ATS': Array(6.02181564, dtype=float64),\n",
" 'ω_ResonatorA': Array(4.99584201, dtype=float64),\n",
" 'ω_ResonatorB': Array(7.00151547, dtype=float64)}"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"metrics0"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "jax-framework",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.18"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading

0 comments on commit 3534ea2

Please sign in to comment.