diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f09136b..da7b4df 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -66,7 +66,7 @@ repos: stages: [manual] # because it's slow # Python - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.5.7 + rev: v0.6.1 hooks: - id: ruff-format args: ["--config", "moyopy/pyproject.toml"] diff --git a/bench/mp/analysis.ipynb b/bench/mp/analysis.ipynb index 8f78926..f75aa16 100644 --- a/bench/mp/analysis.ipynb +++ b/bench/mp/analysis.ipynb @@ -11,9 +11,9 @@ "import matplotlib.pyplot as plt\n", "import seaborn as sns\n", "\n", - "sns.set_context('poster')\n", - "plt.rcParams['grid.linewidth'] = 0.2\n", - "pd.set_option('display.max_rows', 500)" + "sns.set_context(\"poster\")\n", + "plt.rcParams[\"grid.linewidth\"] = 0.2\n", + "pd.set_option(\"display.max_rows\", 500)" ] }, { @@ -211,16 +211,20 @@ ], "source": [ "df = pd.read_json(\"stats.json\")\n", - "df.sort_values(['material_id', 'symprec'], inplace=True)\n", + "df.sort_values([\"material_id\", \"symprec\"], inplace=True)\n", "\n", - "series_moyopy = df.groupby('material_id')['number_moyopy'].apply(list)\n", - "series_spglib = df.groupby('material_id')['number_spglib'].apply(list)\n", + "series_moyopy = df.groupby(\"material_id\")[\"number_moyopy\"].apply(list)\n", + "series_spglib = df.groupby(\"material_id\")[\"number_spglib\"].apply(list)\n", "\n", "df_stat = pd.concat([series_moyopy, series_spglib], axis=1)\n", "# jaccard_index(A, B) := |A ∩ B| / |A ∪ B|\n", - "df_stat['jaccard'] = df_stat.apply(lambda row: len(set(row['number_moyopy']) & set(row['number_spglib'])) / len(set(row['number_moyopy']) | set(row['number_spglib'])), axis=1)\n", - "df_stat['number_moyopy_last'] = df_stat['number_moyopy'].apply(lambda x: x[-1])\n", - "df_stat['number_spglib_last'] = df_stat['number_spglib'].apply(lambda x: x[-1])\n", + "df_stat[\"jaccard\"] = df_stat.apply(\n", + " lambda row: len(set(row[\"number_moyopy\"]) & set(row[\"number_spglib\"]))\n", + " / len(set(row[\"number_moyopy\"]) | set(row[\"number_spglib\"])),\n", + " axis=1,\n", + ")\n", + "df_stat[\"number_moyopy_last\"] = df_stat[\"number_moyopy\"].apply(lambda x: x[-1])\n", + "df_stat[\"number_spglib_last\"] = df_stat[\"number_spglib\"].apply(lambda x: x[-1])\n", "df_stat" ] }, @@ -250,7 +254,7 @@ } ], "source": [ - "df['time_spglib'].sum() / df['time_moyopy'].sum()" + "df[\"time_spglib\"].sum() / df[\"time_moyopy\"].sum()" ] }, { @@ -272,15 +276,17 @@ "source": [ "fig, ax = plt.subplots(figsize=(6.75, 6.75))\n", "# df.plot.scatter(x='time_spglib', y='time_moyopy', ax=ax, facecolors='none', edgecolors='C0')\n", - "ax.scatter(df['time_spglib'], df['time_moyopy'], facecolors='none', edgecolors='C0', s=8, linewidths=1)\n", + "ax.scatter(\n", + " df[\"time_spglib\"], df[\"time_moyopy\"], facecolors=\"none\", edgecolors=\"C0\", s=8, linewidths=1\n", + ")\n", "ax.set_xlim(0, 0.1)\n", "ax.set_ylim(0, 0.1)\n", - "ax.set_xlabel('spglib (s)')\n", - "ax.set_ylabel('moyopy (s)')\n", - "ax.set_aspect('equal')\n", + "ax.set_xlabel(\"spglib (s)\")\n", + "ax.set_ylabel(\"moyopy (s)\")\n", + "ax.set_aspect(\"equal\")\n", "ax.set_title(\"mp_computed_structure_entries\")\n", "ax.grid()\n", - "fig.savefig('mp.png', bbox_inches=\"tight\", pad_inches=0.0, dpi=200)" + "fig.savefig(\"mp.png\", bbox_inches=\"tight\", pad_inches=0.0, dpi=200)" ] }, { @@ -309,7 +315,7 @@ } ], "source": [ - "len(df_stat[df_stat['jaccard'] < 1]) / len(df_stat)" + "len(df_stat[df_stat[\"jaccard\"] < 1]) / len(df_stat)" ] }, { @@ -4017,7 +4023,7 @@ } ], "source": [ - "fig = px.histogram(df_stat[df_stat['jaccard'] < 1], x='jaccard', range_x=[0, 0.9])\n", + "fig = px.histogram(df_stat[df_stat[\"jaccard\"] < 1], x=\"jaccard\", range_x=[0, 0.9])\n", "fig" ] }, @@ -4208,7 +4214,7 @@ } ], "source": [ - "df_stat[df_stat['jaccard'] < 1]" + "df_stat[df_stat[\"jaccard\"] < 1]" ] }, { @@ -7167,7 +7173,9 @@ } ], "source": [ - "df_stat[(df_stat['number_moyopy_last'] < df_stat['number_spglib_last']) & (df_stat['jaccard'] < 1)].sort_values('jaccard')" + "df_stat[\n", + " (df_stat[\"number_moyopy_last\"] < df_stat[\"number_spglib_last\"]) & (df_stat[\"jaccard\"] < 1)\n", + "].sort_values(\"jaccard\")" ] } ],