Skip to content

Commit

Permalink
PyLIQTR update and refactoring (#50)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: zmorrell <[email protected]>
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 5, 2024
1 parent 5030e8e commit 0b56eaa
Show file tree
Hide file tree
Showing 9 changed files with 385 additions and 457 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![pylint](https://img.shields.io/badge/PyLint-9.48-yellow?logo=python&logoColor=white)
![pylint](https://img.shields.io/badge/PyLint-9.47-yellow?logo=python&logoColor=white)

# Quantum Computing Application Specifications

Expand Down
130 changes: 65 additions & 65 deletions notebooks/HighTemperatureSuperConductorExample.ipynb

Large diffs are not rendered by default.

276 changes: 98 additions & 178 deletions notebooks/MagneticLattices.ipynb

Large diffs are not rendered by default.

312 changes: 156 additions & 156 deletions notebooks/PhotosynthesisExample.ipynb

Large diffs are not rendered by default.

68 changes: 26 additions & 42 deletions notebooks/RuClExample.ipynb

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ build-backend = "setuptools.build_meta"

[project]
name = "qca"
version = "0.0.1"
version = "0.1.0"
dynamic = ["dependencies"]
requires-python = ">=3.9"
requires-python = ">=3.9, <=3.12"
description = "Documentation of Applications for Quantum Computers"
readme = "README.md"
license = {file = "License.md"}
Expand Down
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
cirq == 1.3.0.dev20231102230836
pyLIQTR == 1.2.0
matplotlib
networkx
numpy
openfermion
openfermionpyscf
pandas
pyLIQTR ==1.0.0
21 changes: 15 additions & 6 deletions src/qca/utils/algo_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@
from pyLIQTR.utils.utils import open_fermion_to_qasm
from pyLIQTR.circuits.qsp import generate_QSP_circuit
from pyLIQTR.PhaseEstimation.pe import PhaseEstimation
from pyLIQTR.utils.qsp_helpers import print_to_openqasm
from pyLIQTR.gate_decomp.cirq_transforms import clifford_plus_t_direct_transform
from pyLIQTR.phase_factors.fourier_response.fourier_response import Angler_fourier_response

from qca.utils.utils import circuit_estimate, estimate_cpt_resources, EstimateMetaData, re_as_json
from qca.utils.utils import (
re_as_json,
write_qasm,
circuit_estimate,
estimate_cpt_resources,
EstimateMetaData
)

def estimate_qsp(
pyliqtr_hamiltonian: Hamiltonian,
Expand Down Expand Up @@ -149,11 +154,15 @@ def estimate_trotter(

if write_circuits:
outfile_qasm_trotter = f'{outdir}Trotter_Unitary.qasm'
write_qasm(
circuit=trotter_circuit_qasm,
fname=outfile_qasm_trotter
)
outfile_qasm_cpt = f'{outdir}Trotter_Unitary.cpt.qasm'
with open(outfile_qasm_trotter, 'w', encoding='utf-8') as f:
print_to_openqasm(f, trotter_circuit_qasm, trotter_circuit_qasm.all_qubits())
with open(outfile_qasm_cpt, 'w', encoding='utf-8') as f:
print_to_openqasm(f, cpt_trotter, qubits=cpt_trotter.all_qubits())
write_qasm(
circuit=cpt_trotter,
fname=outfile_qasm_cpt
)

logical_re = estimate_cpt_resources(
cpt_circuit=cpt_trotter,
Expand Down
26 changes: 21 additions & 5 deletions src/qca/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

import cirq

from pyLIQTR.utils.printing import openqasm
from pyLIQTR.utils.utils import count_T_gates
from pyLIQTR.utils.qsp_helpers import print_to_openqasm
from pyLIQTR.gate_decomp.cirq_transforms import clifford_plus_t_direct_transform

@dataclass
Expand Down Expand Up @@ -199,6 +199,18 @@ def grab_single_step_estimates(num_qubits: int, main_estimates: dict, algo_name:
}
}

def write_qasm(
circuit: cirq.AbstractCircuit,
fname: str
):
qasm_iter = openqasm(
circuit=circuit,
rotation_allowed=True,
)
qasm_str = ' \n'.join([qasm for qasm in qasm_iter])
with open(fname, 'w', encoding='utf-8') as file:
file.write(qasm_str)

def circuit_estimate(
circuit: cirq.AbstractCircuit,
outdir: str,
Expand Down Expand Up @@ -231,11 +243,15 @@ def circuit_estimate(
print(f' Time to transform decomposed {gate_type_name} circuit to Clifford+T: {cpt_elapsed} seconds')
if write_circuits:
outfile_qasm_decomposed = f'{outdir}{gate_type_name}.decomposed.qasm'
write_qasm(
circuit=decomposed_circuit,
fname=outfile_qasm_decomposed
)
outfile_qasm_cpt = f'{outdir}{gate_type_name}.cpt.qasm'
with open(outfile_qasm_decomposed, 'w', encoding='utf-8') as f:
print_to_openqasm(f, decomposed_circuit, qubits=decomposed_circuit.all_qubits())
with open(outfile_qasm_cpt, 'w', encoding='utf-8') as f:
print_to_openqasm(f, cpt_circuit, qubits=cpt_circuit.all_qubits())
write_qasm(
circuit=cpt_circuit,
fname=outfile_qasm_cpt
)

subcircuit_counts[gate_type] = [1, cpt_circuit, gate_type_name]

Expand Down

0 comments on commit 0b56eaa

Please sign in to comment.