Skip to content

Commit

Permalink
Removed deepcopy stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
gonfeco committed Sep 12, 2023
1 parent c532724 commit 3079546
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 292 deletions.
16 changes: 6 additions & 10 deletions tnbs/BTC_02_AE/QQuantLib/AA/amplitude_amplification.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"""

import time
from copy import deepcopy
import numpy as np
import qat.lang.AQASM as qlm

Expand Down Expand Up @@ -263,7 +262,6 @@ def create_u_gate(oracle: qlm.QRoutine, mcz_qlm=True):
----------
u_gate : QLM gate
"""
oracle_cp = deepcopy(oracle)
number_qubits = oracle.arity

@qlm.build_gate("U_" + str(time.time_ns()), [], arity=number_qubits)
Expand Down Expand Up @@ -303,15 +301,14 @@ def grover(oracle: qlm.QRoutine, target: np.ndarray, index: np.ndarray, mcz_qlm=
----------
grover_gate : QLM gate
"""
oracle_cp = deepcopy(oracle)
number_qubits = oracle_cp.arity
number_qubits = oracle.arity

@qlm.build_gate("G_" + str(time.time_ns()), [], arity=number_qubits)
def grover_gate():
routine = qlm.QRoutine()
register = routine.new_wires(number_qubits)
routine.apply(create_u0_gate(oracle_cp, target, index, mcz_qlm), register)
routine.apply(create_u_gate(oracle_cp, mcz_qlm), register)
routine.apply(create_u0_gate(oracle, target, index, mcz_qlm), register)
routine.apply(create_u_gate(oracle, mcz_qlm), register)
return routine

return grover_gate()
Expand Down Expand Up @@ -341,8 +338,7 @@ def grover_extended(oracle: qlm.QRoutine, target: np.ndarray, index: np.ndarray,
----------
grover_gate : QLM gate
"""
oracle_cp = deepcopy(oracle)
number_qubits = oracle_cp.arity
number_qubits = oracle.arity
@qlm.build_gate("G'_" + str(time.time_ns()), [], arity=number_qubits)
def grover_extended_gate():
routine = qlm.QRoutine()
Expand All @@ -352,12 +348,12 @@ def grover_extended_gate():
reflection(np.zeros(number_qubits, dtype=int), mcz_qlm),
register
)
routine.apply(oracle_cp, register)
routine.apply(oracle, register)
routine.apply(
reflection(target, mcz_qlm),
[register[i] for i in index]
)
routine.apply(oracle_cp.dag(), register)
routine.apply(oracle.dag(), register)
return routine

return grover_extended_gate()
5 changes: 2 additions & 3 deletions tnbs/BTC_02_AE/QQuantLib/AE/ae_classical_qpe.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"""

import time
from copy import deepcopy
import numpy as np
import qat.lang.AQASM as qlm
import sys
Expand Down Expand Up @@ -64,7 +63,7 @@ def __init__(self, oracle: qlm.QRoutine, target: list, index: list, **kwargs):
"""
# Setting attributes
self._oracle = deepcopy(oracle)
self._oracle = oracle
self._target = check_list_type(target, int)
self._index = check_list_type(index, int)

Expand Down Expand Up @@ -113,7 +112,7 @@ def oracle(self, value):
"""
setter of the oracle property
"""
self._oracle = deepcopy(value)
self._oracle = value
self._grover_oracle = grover(
self.oracle, self.target, self.index, mcz_qlm=self.mcz_qlm
)
Expand Down
5 changes: 2 additions & 3 deletions tnbs/BTC_02_AE/QQuantLib/AE/ae_iterative_quantum_pe.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"""

import time
from copy import deepcopy
import numpy as np
import qat.lang.AQASM as qlm
import sys
Expand Down Expand Up @@ -62,7 +61,7 @@ def __init__(self, oracle: qlm.QRoutine, target: list, index: list, **kwargs):
"""
# Setting attributes
self._oracle = deepcopy(oracle)
self._oracle = oracle
self._target = check_list_type(target, int)
self._index = check_list_type(index, int)

Expand Down Expand Up @@ -108,7 +107,7 @@ def oracle(self, value):
"""
setter of the oracle property
"""
self._oracle = deepcopy(value)
self._oracle = value
self._grover_oracle = grover(
self.oracle, self.target, self.index, mcz_qlm=self.mcz_qlm
)
Expand Down
5 changes: 2 additions & 3 deletions tnbs/BTC_02_AE/QQuantLib/AE/iterative_quantum_ae.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"""

import time
from copy import deepcopy
import numpy as np
import pandas as pd
import qat.lang.AQASM as qlm
Expand Down Expand Up @@ -63,7 +62,7 @@ def __init__(self, oracle: qlm.QRoutine, target: list, index: list, **kwargs):
Method for initializing the class
"""
# Setting attributes
self._oracle = deepcopy(oracle)
self._oracle = oracle
self._target = check_list_type(target, int)
self._index = check_list_type(index, int)

Expand Down Expand Up @@ -111,7 +110,7 @@ def oracle(self, value):
"""
setter of the oracle property
"""
self._oracle = deepcopy(value)
self._oracle = value
self._grover_oracle = grover(
self._oracle, self.target, self.index, mcz_qlm=self.mcz_qlm
)
Expand Down
5 changes: 2 additions & 3 deletions tnbs/BTC_02_AE/QQuantLib/AE/maximum_likelihood_ae.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"""

import time
from copy import deepcopy
from functools import partial
import numpy as np
import pandas as pd
Expand Down Expand Up @@ -68,7 +67,7 @@ def __init__(self, oracle: qlm.QRoutine, target: list, index: list, **kwargs):
"""
# Setting attributes
self._oracle = deepcopy(oracle)
self._oracle = oracle
self._target = check_list_type(target, int)
self._index = check_list_type(index, int)

Expand Down Expand Up @@ -134,7 +133,7 @@ def oracle(self, value):
"""
setter of the oracle property
"""
self._oracle = deepcopy(value)
self._oracle = value
self._grover_oracle = grover(
self.oracle, self.target, self.index, mcz_qlm=self.mcz_qlm
)
Expand Down
5 changes: 2 additions & 3 deletions tnbs/BTC_02_AE/QQuantLib/AE/montecarlo_ae.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"""

import time
from copy import deepcopy
import numpy as np
import pandas as pd
import qat.lang.AQASM as qlm
Expand Down Expand Up @@ -54,7 +53,7 @@ def __init__(self, oracle: qlm.QRoutine, target: list, index: list, **kwargs):
Method for initializing the class
"""
# Setting attributes
self._oracle = deepcopy(oracle)
self._oracle = oracle
self._target = check_list_type(target, int)
self._index = check_list_type(index, int)

Expand Down Expand Up @@ -96,7 +95,7 @@ def oracle(self, value):
"""
setter of the oracle property
"""
self._oracle = deepcopy(value)
self._oracle = value

@property
def target(self):
Expand Down
5 changes: 2 additions & 3 deletions tnbs/BTC_02_AE/QQuantLib/AE/real_quantum_ae.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"""

import time
from copy import deepcopy
import numpy as np
import pandas as pd
import qat.lang.AQASM as qlm
Expand Down Expand Up @@ -64,7 +63,7 @@ def __init__(self, oracle: qlm.QRoutine, target: list, index: list, **kwargs):
"""
###########################################
# Setting attributes
self._oracle = deepcopy(oracle)
self._oracle = oracle
self._target = check_list_type(target, int)
self._index = check_list_type(index, int)

Expand Down Expand Up @@ -113,7 +112,7 @@ def oracle(self, value):
"""
setter of the oracle property
"""
self._oracle = deepcopy(value)
self._oracle = value
self._grover_oracle = grover(
self._oracle, self.target, self.index, mcz_qlm=self.mcz_qlm
)
Expand Down
3 changes: 1 addition & 2 deletions tnbs/BTC_02_AE/QQuantLib/PE/iterative_quantum_pe.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"""

import time
from copy import deepcopy
import numpy as np
import pandas as pd
import qat.lang.AQASM as qlm
Expand Down Expand Up @@ -141,7 +140,7 @@ def init_iqpe(self):
"""
self.restart()
# Create quantum program based on initial state
self.q_prog = create_qprogram(deepcopy(self.initial_state))
self.q_prog = create_qprogram(self.initial_state)
self.q_aux = self.q_prog.qalloc(1)
self.c_bits = self.q_prog.calloc(self.cbits_number)

Expand Down
6 changes: 2 additions & 4 deletions tnbs/BTC_02_AE/QQuantLib/utils/data_extracting.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"""

import time
from copy import deepcopy
import numpy as np
import pandas as pd
import qat.lang.AQASM as qlm
Expand Down Expand Up @@ -55,7 +54,7 @@ def get_results(
#print("BE AWARE!! linalg_qpu : {}".format(linalg_qpu))
# if type(quantum_object) == qlm.Program:
if isinstance(quantum_object, qlm.Program):
q_prog = deepcopy(quantum_object)
q_prog = quantum_object
arity = q_prog.qbit_count
else:
q_prog = create_qprogram(quantum_object)
Expand Down Expand Up @@ -140,8 +139,7 @@ def create_qcircuit(prog_q):
circuit : QLM circuit
"""
q_prog = deepcopy(prog_q)
circuit = q_prog.to_circ(submatrices_only=True)#, inline=True)
circuit = prog_q.to_circ(submatrices_only=True)#, inline=True)
return circuit


Expand Down
11 changes: 6 additions & 5 deletions tnbs/BTC_02_AE/my_benchmark_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def build_iterator(**kwargs):

list4int = [
kwargs['list_of_qbits'],
[0, 1],
kwargs['kernel_configuration']['integrals'],
]

iterator = it.product(*list4int)
Expand Down Expand Up @@ -120,7 +120,7 @@ def compute_samples(**kwargs):
#statististical significance. Depends on benchmark kernel

#Desired Relative Error for the elapsed Time
relative_error = bench_conf.get("relative_error", None)
relative_error = kwargs.get("relative_error", None)
if relative_error is None:
relative_error = 0.05
# Compute samples for realtive error metrics:
Expand All @@ -129,7 +129,7 @@ def compute_samples(**kwargs):
(relative_error * metrics[['elapsed_time', 'oracle_calls']].mean()))**2

#Desired Absolute Error.
absolute_error = bench_conf.get("absolute_error", None)
absolute_error = kwargs.get("absolute_error", None)
if absolute_error is None:
absolute_error = 1e-4
samples_ae = (zalpha * metrics[['absolute_error_sum']].std() \
Expand Down Expand Up @@ -300,8 +300,7 @@ def exe(self):

ae_problem.update({
"qpu": "c",
"relative_error": None,
"absolute_error": None
"integrals": [0]
})

benchmark_arguments = {
Expand All @@ -317,6 +316,8 @@ def exe(self):
"summary_results": "{}_SummaryResults.csv".format(AE),
#Computing Repetitions stuff
"alpha": None,
"relative_error": None,
"absolute_error": None,
"min_meas": None,
"max_meas": None,
#List number of qubits tested
Expand Down
Loading

0 comments on commit 3079546

Please sign in to comment.