Skip to content

Commit

Permalink
fixed gsee issue where it wasn't counting the current number of gates…
Browse files Browse the repository at this point in the history
… and depth for GSEE in the fermihubbard notebook (#12)
  • Loading branch information
JonhasSC authored Mar 13, 2024
1 parent 89b78c7 commit 2f154af
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 49 deletions.
63 changes: 46 additions & 17 deletions notebooks/HighTemperatureSuperConductorExample.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,18 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 1,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/jonhas/anaconda3/lib/python3.11/site-packages/attr/_make.py:918: RuntimeWarning: Running interpreter doesn't sufficiently support code object introspection. Some features like bare super() or accessing __class__ will not work with slotted classes.\n",
" set_closure_cell(cell, cls)\n"
]
}
],
"source": [
"import time\n",
"import numpy as np\n",
Expand All @@ -43,7 +52,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 2,
"metadata": {},
"outputs": [
{
Expand All @@ -67,7 +76,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 3,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -155,7 +164,7 @@
"-1.0 [15^ 15]"
]
},
"execution_count": 4,
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -171,7 +180,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -189,7 +198,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -224,16 +233,16 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"starting\n",
"current limit time to generate high level: 0.16728520899778232\n",
"ideal time to generate high level: 0.9127594170131488\n"
"current limit time to generate high level: 0.17232737501035444\n",
"ideal time to generate high level: 0.9439791250042617\n"
]
}
],
Expand Down Expand Up @@ -282,30 +291,50 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Estimating Ideal\n",
"Time to estimate Ideal: 266.92374454200035\n",
"Estimating Current Limit\n",
"Time to estimate Current Limit: 55.14061645799666\n"
"Estimating Ideal\n"
]
},
{
"ename": "KeyboardInterrupt",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[7], line 3\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mEstimating Ideal\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m 2\u001b[0m t0 \u001b[38;5;241m=\u001b[39m time\u001b[38;5;241m.\u001b[39mperf_counter()\n\u001b[0;32m----> 3\u001b[0m estimate_gsee(gse_circuit_ideal, outdir\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mGSE/\u001b[39m\u001b[38;5;124m'\u001b[39m, circuit_name\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mideal\u001b[39m\u001b[38;5;124m'\u001b[39m, write_circuits\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n\u001b[1;32m 4\u001b[0m t1 \u001b[38;5;241m=\u001b[39m time\u001b[38;5;241m.\u001b[39mperf_counter()\n\u001b[1;32m 5\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mTime to estimate Ideal: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mt1\u001b[38;5;241m-\u001b[39mt0\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m'\u001b[39m)\n",
"File \u001b[0;32m~/qc-applications/src/qca/utils/utils.py:100\u001b[0m, in \u001b[0;36mestimate_gsee\u001b[0;34m(circuit, outdir, circuit_name, write_circuits)\u001b[0m\n\u001b[1;32m 98\u001b[0m subcircuit_counts[gate_type] \u001b[38;5;241m+\u001b[39m\u001b[38;5;241m=\u001b[39m \u001b[38;5;241m1\u001b[39m\n\u001b[1;32m 99\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m--> 100\u001b[0m decomposed_circuit \u001b[38;5;241m=\u001b[39m circuit_decompose_once(circuit_decompose_once(Circuit(operation)))\n\u001b[1;32m 101\u001b[0m cpt_circuit \u001b[38;5;241m=\u001b[39m clifford_plus_t_direct_transform(decomposed_circuit)\n\u001b[1;32m 103\u001b[0m \u001b[38;5;66;03m# outfile_qasm_decomposed = outdir+str(gate_type)[8:-2]+\".decomposed.qasm\"\u001b[39;00m\n\u001b[1;32m 104\u001b[0m \u001b[38;5;66;03m# outfile_qasm_cpt = outdir+str(gate_type)[8:-2]+\".cpt.qasm\"\u001b[39;00m\n",
"File \u001b[0;32m~/anaconda3/lib/python3.11/site-packages/pyLIQTR/utils/qsp_helpers.py:382\u001b[0m, in \u001b[0;36mcircuit_decompose_once\u001b[0;34m(circuit, debug)\u001b[0m\n\u001b[1;32m 380\u001b[0m \u001b[38;5;28;01mcontinue\u001b[39;00m\n\u001b[1;32m 381\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m--> 382\u001b[0m tmp_gates \u001b[38;5;241m=\u001b[39m cirq\u001b[38;5;241m.\u001b[39mdecompose_once(op)\n\u001b[1;32m 383\u001b[0m decomp_gates \u001b[38;5;241m=\u001b[39m []\n\u001b[1;32m 385\u001b[0m \u001b[38;5;66;03m# Note: If this decomposes into a MatrixGate, \u001b[39;00m\n\u001b[1;32m 386\u001b[0m \u001b[38;5;66;03m# lets decompose it once more so its not \u001b[39;00m\n\u001b[1;32m 387\u001b[0m \u001b[38;5;66;03m# a MatrixGate\u001b[39;00m\n",
"File \u001b[0;32m~/anaconda3/lib/python3.11/site-packages/cirq/protocols/decompose_protocol.py:384\u001b[0m, in \u001b[0;36mdecompose_once\u001b[0;34m(val, default, flatten, context, *args, **kwargs)\u001b[0m\n\u001b[1;32m 381\u001b[0m decomposed \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mNotImplemented\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m method \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;28;01melse\u001b[39;00m method(\u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[1;32m 383\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m decomposed \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28mNotImplemented\u001b[39m \u001b[38;5;129;01mand\u001b[39;00m decomposed \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[0;32m--> 384\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mlist\u001b[39m(ops\u001b[38;5;241m.\u001b[39mflatten_to_ops(decomposed)) \u001b[38;5;28;01mif\u001b[39;00m flatten \u001b[38;5;28;01melse\u001b[39;00m decomposed\n\u001b[1;32m 386\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m default \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m RaiseTypeErrorIfNotProvided:\n\u001b[1;32m 387\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m default\n",
"File \u001b[0;32m~/anaconda3/lib/python3.11/site-packages/cirq/ops/op_tree.py:112\u001b[0m, in \u001b[0;36mflatten_to_ops\u001b[0;34m(root)\u001b[0m\n\u001b[1;32m 110\u001b[0m \u001b[38;5;28;01myield\u001b[39;00m root\n\u001b[1;32m 111\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(root, Iterable) \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(root, \u001b[38;5;28mstr\u001b[39m):\n\u001b[0;32m--> 112\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m subtree \u001b[38;5;129;01min\u001b[39;00m root:\n\u001b[1;32m 113\u001b[0m \u001b[38;5;28;01myield from\u001b[39;00m flatten_to_ops(subtree)\n\u001b[1;32m 114\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n",
"File \u001b[0;32m~/anaconda3/lib/python3.11/site-packages/pyLIQTR/PhaseEstimation/pe_gates.py:117\u001b[0m, in \u001b[0;36mTrotter_Unitary._decompose_\u001b[0;34m(self, qubits)\u001b[0m\n\u001b[1;32m 115\u001b[0m jw_ham_trotterized_generator \u001b[38;5;241m=\u001b[39m trotterize_exp_qubop_to_qasm(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mjw_ham\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m2\u001b[39m\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39m(\u001b[38;5;241m1\u001b[39m)\u001b[38;5;241m*\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39moperator_power, evolution_time\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mev_time, trotter_number\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mtrot_num, trotter_order\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mtrot_ord)\n\u001b[1;32m 116\u001b[0m jw_ham_trotterized_circuit \u001b[38;5;241m=\u001b[39m open_fermion_to_qasm(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mnum_qubits(), jw_ham_trotterized_generator, reg_name\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mreg\u001b[39m\u001b[38;5;124m'\u001b[39m) \n\u001b[0;32m--> 117\u001b[0m tmp_circuit \u001b[38;5;241m=\u001b[39m qasm_import\u001b[38;5;241m.\u001b[39mcircuit_from_qasm(jw_ham_trotterized_circuit)\n\u001b[1;32m 119\u001b[0m \u001b[38;5;66;03m# Apply control operations on the z-rotations:\u001b[39;00m\n\u001b[1;32m 120\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m _ \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mrange\u001b[39m(\u001b[38;5;241m2\u001b[39m\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mprec_order):\n",
"File \u001b[0;32m~/anaconda3/lib/python3.11/site-packages/cirq/contrib/qasm_import/qasm.py:29\u001b[0m, in \u001b[0;36mcircuit_from_qasm\u001b[0;34m(qasm)\u001b[0m\n\u001b[1;32m 19\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mcircuit_from_qasm\u001b[39m(qasm: \u001b[38;5;28mstr\u001b[39m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m circuits\u001b[38;5;241m.\u001b[39mCircuit:\n\u001b[1;32m 20\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"Parses an OpenQASM string to `cirq.Circuit`.\u001b[39;00m\n\u001b[1;32m 21\u001b[0m \n\u001b[1;32m 22\u001b[0m \u001b[38;5;124;03m Args:\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 26\u001b[0m \u001b[38;5;124;03m The parsed circuit\u001b[39;00m\n\u001b[1;32m 27\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[0;32m---> 29\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m QasmParser()\u001b[38;5;241m.\u001b[39mparse(qasm)\u001b[38;5;241m.\u001b[39mcircuit\n",
"File \u001b[0;32m~/anaconda3/lib/python3.11/site-packages/cirq/contrib/qasm_import/_parser.py:538\u001b[0m, in \u001b[0;36mQasmParser.parse\u001b[0;34m(self, qasm)\u001b[0m\n\u001b[1;32m 536\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mqasm \u001b[38;5;241m=\u001b[39m qasm\n\u001b[1;32m 537\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mlexer\u001b[38;5;241m.\u001b[39minput(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mqasm)\n\u001b[0;32m--> 538\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mparsedQasm \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mparser\u001b[38;5;241m.\u001b[39mparse(lexer\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mlexer)\n\u001b[1;32m 539\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mparsedQasm\n",
"File \u001b[0;32m~/anaconda3/lib/python3.11/site-packages/ply/yacc.py:333\u001b[0m, in \u001b[0;36mLRParser.parse\u001b[0;34m(self, input, lexer, debug, tracking, tokenfunc)\u001b[0m\n\u001b[1;32m 331\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mparseopt(\u001b[38;5;28minput\u001b[39m, lexer, debug, tracking, tokenfunc)\n\u001b[1;32m 332\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m--> 333\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mparseopt_notrack(\u001b[38;5;28minput\u001b[39m, lexer, debug, tracking, tokenfunc)\n",
"File \u001b[0;32m~/anaconda3/lib/python3.11/site-packages/ply/yacc.py:1063\u001b[0m, in \u001b[0;36mLRParser.parseopt_notrack\u001b[0;34m(self, input, lexer, debug, tracking, tokenfunc)\u001b[0m\n\u001b[1;32m 1061\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m lookahead:\n\u001b[1;32m 1062\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m lookaheadstack:\n\u001b[0;32m-> 1063\u001b[0m lookahead \u001b[38;5;241m=\u001b[39m get_token() \u001b[38;5;66;03m# Get the next token\u001b[39;00m\n\u001b[1;32m 1064\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 1065\u001b[0m lookahead \u001b[38;5;241m=\u001b[39m lookaheadstack\u001b[38;5;241m.\u001b[39mpop()\n",
"File \u001b[0;32m~/anaconda3/lib/python3.11/site-packages/cirq/contrib/qasm_import/_lexer.py:124\u001b[0m, in \u001b[0;36mQasmLexer.token\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 123\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mtoken\u001b[39m(\u001b[38;5;28mself\u001b[39m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Optional[lex\u001b[38;5;241m.\u001b[39mToken]:\n\u001b[0;32m--> 124\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mlex\u001b[38;5;241m.\u001b[39mtoken()\n",
"File \u001b[0;32m~/anaconda3/lib/python3.11/site-packages/ply/lex.py:350\u001b[0m, in \u001b[0;36mLexer.token\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 347\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mlexmatch \u001b[38;5;241m=\u001b[39m m\n\u001b[1;32m 348\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mlexpos \u001b[38;5;241m=\u001b[39m lexpos\n\u001b[0;32m--> 350\u001b[0m newtok \u001b[38;5;241m=\u001b[39m func(tok)\n\u001b[1;32m 352\u001b[0m \u001b[38;5;66;03m# Every function must return a token, if nothing, we just move to next token\u001b[39;00m\n\u001b[1;32m 353\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m newtok:\n",
"File \u001b[0;32m~/anaconda3/lib/python3.11/site-packages/cirq/contrib/qasm_import/_lexer.py:110\u001b[0m, in \u001b[0;36mQasmLexer.t_ID\u001b[0;34m(self, t)\u001b[0m\n\u001b[1;32m 107\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"==\"\"\"\u001b[39;00m\n\u001b[1;32m 108\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m t\n\u001b[0;32m--> 110\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mt_ID\u001b[39m(\u001b[38;5;28mself\u001b[39m, t):\n\u001b[1;32m 111\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124mr\u001b[39m\u001b[38;5;124;03m\"\"\"[a-zA-Z][a-zA-Z\\d_]*\"\"\"\u001b[39;00m\n\u001b[1;32m 112\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m t\n",
"\u001b[0;31mKeyboardInterrupt\u001b[0m: "
]
}
],
"source": [
"print('Estimating Ideal')\n",
"t0 = time.perf_counter()\n",
"estimate_gsee(gse_circuit_ideal, outdir='GSE/', circuit_name='ideal')\n",
"estimate_gsee(gse_circuit_ideal, outdir='GSE/', circuit_name='ideal', write_circuits=True)\n",
"t1 = time.perf_counter()\n",
"print(f'Time to estimate Ideal: {t1-t0}')\n",
"\n",
"print('Estimating Current Limit')\n",
"t0 = time.perf_counter()\n",
"estimate_gsee(gse_circuit_current_limit, outdir='GSE/', circuit_name='current_limit')\n",
"estimate_gsee(gse_circuit_current_limit, outdir='GSE/', circuit_name='current_limit', write_circuits=True)\n",
"t1 = time.perf_counter()\n",
"print(f'Time to estimate Current Limit: {t1-t0}')"
]
Expand Down
63 changes: 31 additions & 32 deletions src/qca/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,42 +82,41 @@ def estimate_gsee(
write_circuits: bool = False) -> None:
if not os.path.exists(outdir):
os.makedirs(outdir)

t_counts = {}
gate_counts = {}
clifford_counts = {}
subcircuit_counts = {}
subcircuit_depths = {}

subcircuit_counts = dict()
t_counts = dict()
clifford_counts = dict()
gate_counts = dict()
subcircuit_depths = dict()
outfile_data = f'{outdir}{circuit_name}_high_level.dat'

for moment in circuit:
for operation in moment:
gate_type = type(operation.gate)
if gate_type in subcircuit_counts:
subcircuit_counts[gate_type] += 1
else:
decomposed_circuit = circuit_decompose_once(
circuit_decompose_once(Circuit(operation)))
cpt_circuit = clifford_plus_t_direct_transform(
decomposed_circuit)

decomposed_circuit = circuit_decompose_once(circuit_decompose_once(Circuit(operation)))
cpt_circuit = clifford_plus_t_direct_transform(decomposed_circuit)

outfile_qasm_decomposed = f'{outdir}{str(gate_type)[8:-2]}.decomposed.qasm'
outfile_qasm_cpt = f'{outdir}{str(gate_type)[8:-2]}.cpt.qasm'

if write_circuits:
outfile_qasm_decomposed = f'{outdir}{str(gate_type)[8:-2]}.decomposed.qasm'
outfile_qasm_cpt = f'{outdir}{str(gate_type)[8:-2]}.cpt.qasm'
QasmOutput(
decomposed_circuit,
decomposed_circuit.all_qubits()).save(outfile_qasm_decomposed)

QasmOutput(cpt_circuit,
cpt_circuit.all_qubits()).save(outfile_qasm_cpt)

subcircuit_counts[gate_type] = 1
subcircuit_depths[gate_type] = len(cpt_circuit)
t_counts[gate_type] = count_T_gates(cpt_circuit)
gate_counts[gate_type] = count_gates(cpt_circuit)
clifford_counts[gate_type] = gate_counts[gate_type] - \
t_counts[gate_type]

clifford_counts[gate_type] = gate_counts[gate_type] - t_counts[gate_type]

total_gate_count = 0
total_gate_depth = 0
total_T_count = 0
Expand All @@ -127,17 +126,17 @@ def estimate_gsee(
total_gate_depth += subcircuit_counts[gate] * subcircuit_depths[gate]
total_T_count += subcircuit_counts[gate] * t_counts[gate]
total_clifford_count += subcircuit_counts[gate] * clifford_counts[gate]
with open(outfile_data, 'w', encoding='utf-8') as file:
file.write(f'Logical Qubit Count: {len(circuit.all_qubits())}\n')
file.write(f'Total Gate Count: {total_gate_count}\n')
file.write(f'Total Gate Depth: {total_gate_depth}\n')
file.write(f'Total T Count: {total_T_count}\n')
file.write(f'Total Clifford Count: {total_clifford_count}\n')
file.write('Subcircuit Info:\n')
with open(outfile_data, 'w') as f:
f.write(str("Logical Qubit Count:"+str(len(circuit.all_qubits()))+"\n"))
f.write(str("Total Gate Count:"+str(total_gate_count)+"\n"))
f.write(str("Total Gate Depth:"+str(total_gate_depth)+"\n"))
f.write(str("Total T Count:"+str(total_T_count)+"\n"))
f.write(str("Total Clifford Count:"+str(total_clifford_count)+"\n"))
f.write("Subcircuit Info:\n")
for gate in subcircuit_counts:
file.write(f'{gate}\n')
file.write(f'Subcircuit Occurrences: {subcircuit_counts[gate]}\n')
file.write(f'Gate count: {gate_counts[gate]}\n')
file.write(f'Gate depth: {subcircuit_counts[gate]}\n')
file.write(f'T Count: {t_counts[gate]}\n')
file.write(f'Clifford Count: {clifford_counts[gate]}\n')
f.write(str(str(gate)+"\n"))
f.write(str("Subcircuit Occurrences:"+str(subcircuit_counts[gate])+"\n"))
f.write(str("Gate Count:"+str(gate_counts[gate])+"\n"))
f.write(str("Gate Depth:"+str(subcircuit_depths[gate])+"\n"))
f.write(str("T Count:"+str(t_counts[gate])+"\n"))
f.write(str("Clifford Count:"+str(clifford_counts[gate])+"\n"))

0 comments on commit 2f154af

Please sign in to comment.