Skip to content

Commit

Permalink
changed field from value_per_circuit to value. Additionally, cleaned …
Browse files Browse the repository at this point in the history
…up some code to make sure we getting right value per t gate
  • Loading branch information
JonhasSC committed Jan 21, 2025
1 parent ee7bc72 commit 58783ea
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 59 deletions.
8 changes: 3 additions & 5 deletions notebooks/DickeModelExample.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,6 @@
"print()\n",
"print('Tavis-Cummings Hamiltonian')\n",
"print(H_tavis_cummings)\n",
"#print(g_dicke.nodes)\n",
"#print(g_dicke.edges)\n",
"pos = get_node_attributes(g_dicke, 'pos')\n",
"labels = get_node_attributes(g_dicke, 'label')\n",
"draw(g_dicke, pos=pos, labels=labels, with_labels=True)\n",
Expand Down Expand Up @@ -308,7 +306,7 @@
"print('starting')\n",
"total_value = 0\n",
"repetitions = 1\n",
"value_per_circuit=total_value / repetitions\n",
"value=total_value / repetitions\n",
"\n",
"\n",
"dicke_metadata = GSEEMetaData(\n",
Expand All @@ -317,7 +315,7 @@
" category='scientific',\n",
" size=f'{n_b} + 1 + {n_s}',\n",
" task='Ground State Energy Estimation',\n",
" value_per_circuit=value_per_circuit,\n",
" value=value,\n",
" repetitions_per_application=repetitions,\n",
"\n",
" evolution_time=t_dicke,\n",
Expand Down Expand Up @@ -467,7 +465,7 @@
" category='scientific',\n",
" size=f'{n_b} + 1 + {n_s}',\n",
" task='Ground State Energy Estimation',\n",
" value_per_circuit=value_per_circuit,\n",
" value=value,\n",
" repetitions_per_application=repetitions,\n",
"\n",
" \n",
Expand Down
36 changes: 0 additions & 36 deletions notebooks/QCD/forward_scattering_re.json

This file was deleted.

6 changes: 3 additions & 3 deletions scripts/DickeModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ def main(args):
init_state_dicke = [0] * (n_b + n_s + 1) #TODO: use Fock state from Hartree-Fock as initial state

print('starting')
value_per_circuit = value/repetitions
value_per_circuit=6
value = value/repetitions
value=6
#TODO: See if I need to refactor the size string to include the variable names
dicke_metadata = GSEEMetaData(
id=time.time_ns(),
name=name,
category='scientific',
size=f'{n_b} + 1 + {n_s}',
task='Ground State Energy Estimation',
value_per_circuit=value_per_circuit,
value=value,
repetitions_per_application=repetitions,


Expand Down
4 changes: 2 additions & 2 deletions scripts/ExoticPhasesRe.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def gsee_exotic_phases(args, use_square:bool, system_val:float):
nsteps=trotter_steps,
is_extrapolated=True,
gate_synth_accuracy=1e-10,
value_per_circuit=system_val,
value=system_val,
repetitions_per_application=100
)

Expand Down Expand Up @@ -179,7 +179,7 @@ def dynamics(args, system_val:float):
nsteps=trotter_steps,
is_extrapolated=True,
gate_synth_accuracy=1e-10,
value_per_circuit=system_val,
value=system_val,
repetitions_per_application=200
)

Expand Down
2 changes: 1 addition & 1 deletion scripts/HTSC-one-band-RE.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def main(args):
category='scientific',
size=f'{lattice_size}x{lattice_size}',
task='Ground State Energy Estimation',
value_per_circuit=value,
value=value,
repetitions_per_application=repetitions,

evolution_time=evolution_time,
Expand Down
2 changes: 1 addition & 1 deletion scripts/HTSC-three-band-RE.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def main(args):
category='scientific',
size=f'{lattice_size}x{lattice_size}',
task='Ground State Energy Estimation',
value_per_circuit=value,
value=value,
repetitions_per_application=repetitions,

evolution_time=evolution_time,
Expand Down
2 changes: 1 addition & 1 deletion scripts/HTSC-two-band-RE.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def main(args):
category='scientific',
size=f'{lattice_size}x{lattice_size}',
task='Ground State Energy Estimation',
value_per_circuit=value,
value=value,
repetitions_per_application=repetitions,

evolution_time=evolution_time,
Expand Down
4 changes: 2 additions & 2 deletions scripts/TavisCummingsModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ def main(args):
init_state_tavis_cummings = [0] * (n_b + n_s + 1) #TODO: use Fock state from Hartree-Fock as initial state

print('starting')
value_per_circuit = value/repetitions
value = value/repetitions
tavis_cummings_metadata = GSEEMetaData(
id=time.time_ns(),
name=name,
category='scientific',
size=f'{n_b} + 1 + {n_s}',
task='Ground State Energy Estimation',
value_per_circuit=value_per_circuit,
value=value,
repetitions_per_application=repetitions,


Expand Down
4 changes: 4 additions & 0 deletions src/qca/utils/algo_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

from qca.utils.utils import (
gen_json,
gen_value_t_gate,
write_qasm,
grab_circuit_resources,
estimate_cpt_resources,
Expand Down Expand Up @@ -203,6 +204,9 @@ def estimate_trotter(
nsteps=nsteps,
include_nested_resources=include_nested_resources
)
t_count = logical_re['Logical_Abstract']['t_count']
gen_value_t_gate(metadata, t_count)

outfile = f'{outdir}{hamiltonian_name}_re.json'
gen_json(logical_re, outfile, metadata )
return cpt_trotter
Expand Down
4 changes: 2 additions & 2 deletions src/qca/utils/chemistry_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ def gsee_molecular_hamiltonian(
trotter_steps: int,
bits_precision: int,
molecular_hamiltonians: list[molecular_info],
value_per_circuit:float|None=None,
value:float|None=None,
repetitions_per_application:int|None=None,
write_circuits:bool=False,
include_nested_resources:bool=False,
Expand Down Expand Up @@ -338,7 +338,7 @@ def gsee_molecular_hamiltonian(
size=f'{molecular_hamiltonian.n_qubits} qubits',
task='GSEE',
gate_synth_accuracy=gate_synth_accuracy,
value_per_circuit=value_per_circuit,
value=value,
repetitions_per_application=repetitions_per_application,
basis=basis,
evolution_time=ev_time,
Expand Down
13 changes: 7 additions & 6 deletions src/qca/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class EstimateMetaData:
task: str
is_extrapolated: bool=field(default=False, kw_only=True)
gate_synth_accuracy: int | float = field(default=10,kw_only=True)
value_per_circuit: float | None=field(default=None, kw_only=True)
value: float | None=field(default=None, kw_only=True)
value_per_t_gate: float | None=field(default=None,kw_only=True)
repetitions_per_application: int | None=field(default=None, kw_only=True)

Expand Down Expand Up @@ -367,6 +367,10 @@ def gen_json(main_estimate: dict, outfile:str, metadatata: EstimateMetaData|None
main_estimate = re_metadata | main_estimate
re_as_json(main_estimate, outfile)

def gen_value_t_gate(metadata: EstimateMetaData, t_count: int):
if metadata and metadata.value != None and metadata.repetitions_per_application != None:
metadata.value_per_t_gate = metadata.value/t_count

def grab_circuit_resources(circuit: cirq.AbstractCircuit,
outdir: str,
algo_name: str,
Expand Down Expand Up @@ -415,11 +419,8 @@ def grab_circuit_resources(circuit: cirq.AbstractCircuit,

header['subcircuit_info'] = {}

#calculate and insert value_per_t_gate
if metadata != None:
header = estimates['Logical_Abstract']
if (metadata.value_per_circuit != None) and (metadata.repetitions_per_application != None):
metadata.value_per_t_gate = metadata.value_per_circuit/header['t_count']
t_count = estimates['Logical_Abstract']['t_count']
gen_value_t_gate(metadata, t_count)

outfile = f'{outdir}{fname}_re.json'
gen_json(estimates, outfile, metadata)

0 comments on commit 58783ea

Please sign in to comment.