Skip to content

Commit

Permalink
Patch to generate Clifford + T for InverseComposite subcircuit for qs…
Browse files Browse the repository at this point in the history
…p circuits (#29)

* generating Clifford + T for InverseComposite subcircuit for qsp circuits

* Updated pylint badge

* merged with dev

* have trotter re use print_to_openqasm as well

* remove unused import

* Updated pylint badge

* fixing merge conflicts again

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
JonhasSC and github-actions[bot] authored Apr 25, 2024
1 parent fa83f3b commit 44580b4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 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-8.95-yellow?logo=python&logoColor=white)
![pylint](https://img.shields.io/badge/PyLint-9.08-yellow?logo=python&logoColor=white)
# Quantum Computing Application Specifications

Documentation of Applications for Quantum Computers
Expand Down
19 changes: 11 additions & 8 deletions src/qca/utils/algo_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
import random
import numpy as np
import networkx as nx
from cirq import Circuit, QasmOutput
from cirq import Circuit
from openfermion import count_qubits
from cirq.contrib import qasm_import
from pyLIQTR.utils.Hamiltonian import Hamiltonian
from openfermion.ops.operators import QubitOperator
from pyLIQTR.utils.utils import open_fermion_to_qasm
from pyLIQTR.circuits.qsp import generate_QSP_circuit
from pyLIQTR.utils.qsp_helpers import print_to_openqasm
from openfermion.circuits import trotter_steps_required, error_bound
from qca.utils.utils import circuit_estimate, estimate_cpt_resources
from pyLIQTR.gate_decomp.cirq_transforms import clifford_plus_t_direct_transform
Expand Down Expand Up @@ -60,7 +61,7 @@ def find_hamiltonian_ordering(of_hamiltonian: QubitOperator) -> list:
sorted_terms.sort(key=lambda x: len(x) * 100 + ord(x[0][1])) #Z and X get translated to 90 and 88 respectively, multiplying by 100 ensures interacting term weight is considered
one_body_terms_ordered = list(filter(lambda x: len(x) == 1, sorted_terms))
two_body_terms = list(filter(lambda x: len(x) == 2, sorted_terms))

#assigning edge colorings to order two body terms
g = nx.Graph()
for term in two_body_terms:
Expand All @@ -74,7 +75,7 @@ def find_hamiltonian_ordering(of_hamiltonian: QubitOperator) -> list:
color = g.edges[n1,n2]['color']
term = (*term, color)
two_body_terms[i] = term

two_body_terms.sort(key=lambda x: x[2])
two_body_terms_ordered = list()
for (i,term) in enumerate(two_body_terms):
Expand All @@ -98,7 +99,7 @@ def estimate_trotter(
t0 = time.perf_counter()
bounded_error = error_bound(list(openfermion_hamiltonian.get_operators()),tight=False)
nsteps = trotter_steps_required(trotter_error_bound = bounded_error,
time = evolution_time,
time = evolution_time,
energy_precision = energy_precision)
t1 = time.perf_counter()
elapsed = t1 - t0
Expand All @@ -109,7 +110,7 @@ def estimate_trotter(
t1 = time.perf_counter()
elapsed = t1 - t0
print(f'Time to find term ordering: {elapsed} seconds')

t0 = time.perf_counter()
trotter_circuit_of = trotterize_exp_qubop_to_qasm(openfermion_hamiltonian,
trotter_order=2,
Expand All @@ -130,8 +131,10 @@ def estimate_trotter(
if write_circuits:
outfile_qasm_trotter = f'{outdir}Trotter_Unitary.qasm'
outfile_qasm_cpt = f'{outdir}Trotter_Unitary.cpt.qasm'
QasmOutput(cpt_trotter, cpt_trotter.all_qubits()).save(outfile_qasm_cpt)
QasmOutput(trotter_circuit_qasm, trotter_circuit_qasm.all_qubits()).save(outfile_qasm_trotter)
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())

estimate_cpt_resources(
cpt_trotter,
Expand All @@ -141,4 +144,4 @@ def estimate_trotter(
algo_name='Trotter_Step',
trotter_steps=nsteps
)
return cpt_trotter
return cpt_trotter
18 changes: 8 additions & 10 deletions src/qca/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import json
import time
import pandas as pd
import matplotlib.pyplot as plt
from statistics import median
import matplotlib.pyplot as plt
from pyLIQTR.utils.utils import count_T_gates
from cirq import Circuit, QasmOutput, AbstractCircuit
from pyLIQTR.utils.qsp_helpers import circuit_decompose_once
from cirq import Circuit, AbstractCircuit
from pyLIQTR.utils.qsp_helpers import circuit_decompose_once, print_to_openqasm
from pyLIQTR.gate_decomp.cirq_transforms import clifford_plus_t_direct_transform

def count_gates(cpt_circuit: AbstractCircuit) -> int:
Expand Down Expand Up @@ -195,13 +195,11 @@ def circuit_estimate(
if write_circuits:
outfile_qasm_decomposed = f'{outdir}{gate_type_name}.decomposed.qasm'
outfile_qasm_cpt = f'{outdir}{gate_type_name}.cpt.qasm'
QasmOutput(
decomposed_circuit,
decomposed_circuit.all_qubits()).save(outfile_qasm_decomposed)

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

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())

subcircuit_counts[gate_type] = [1, cpt_circuit, gate_type_name]
total_gate_count = 0
total_gate_depth = 0
Expand Down

0 comments on commit 44580b4

Please sign in to comment.