Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
vutuanhai237 committed Sep 19, 2023
1 parent c6cb98b commit 1096b93
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 97 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ __pycache__/
**/.DS_Store
# C extensions
*.so
./codes/qtm
# Distribution / packaging
.Python
build/
Expand Down
96 changes: 0 additions & 96 deletions qtm/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,102 +299,6 @@ def fit_state_preparation(u: types.FunctionType,
else:
return thetas, loss_values

# def fit_state_tomography(u: types.FunctionType,
# vdagger: qiskit.QuantumCircuit,
# thetas: np.ndarray,
# num_steps: int,
# loss_func: types.FunctionType,
# optimizer: types.FunctionType,
# verbose: int = 0,
# is_return_all_thetas: bool = False,
# **kwargs):
# """Return the new thetas that fit with the circuit from create_vdagger_func function

# Args:
# - u (QuantumCircuit): fitting circuit
# - create_vdagger_func (types.FunctionType): added circuit function
# - thetas (np.ndarray): parameters
# - num_steps (Int): number of iterations
# - loss_func (types.FunctionType): loss function
# - optimizer (types.FunctionType): otimizer function
# - verbose (Int): the seeing level of the fitting process (0: nothing, 1: progress bar, 2: one line per step)
# - **kwargs: additional parameters for create_circuit_func()

# Returns:
# - thetas (np.ndarray): the optimized parameters
# - loss_values (np.ndarray): the list of loss_value
# """
# if verbose == 1:
# bar = qtm.progress_bar.ProgressBar(max_value=num_steps, disable=False)
# thetass = []
# loss_values = []
# n = vdagger.num_qubits
# uvaddager = u.compose(vdagger)
# for i in range(0, num_steps):
# grad_loss = qtm.base.grad_loss(
# u, create_vdagger_func, thetas, **kwargs)
# optimizer_name = optimizer.__name__

# if optimizer_name == 'sgd':
# thetas = qtm.optimizer.sgd(thetas, grad_loss)

# elif optimizer_name == 'adam':
# if i == 0:
# m, v = list(np.zeros(thetas.shape[0])), list(
# np.zeros(thetas.shape[0]))
# thetas = qtm.optimizer.adam(thetas, m, v, i, grad_loss)

# elif 'qng' in optimizer_name:
# grad_psi1 = qtm.base.grad_psi(u,
# create_vdagger_func,
# thetas,
# r=qtm.constant.two_term_psr['s'],
# s=np.pi,
# **kwargs)
# u_copy = create_vdagger_func(u.copy(), thetas, **kwargs)
# psi = qiskit.quantum_info.Statevector.from_instruction(u_copy).data
# psi = np.expand_dims(psi, 1)
# if optimizer_name == 'qng_fubini_study':
# G = qtm.fubini_study.qng(
# u.copy(), thetas, create_vdagger_func, **kwargs)
# thetas = qtm.optimizer.qng_fubini_study(thetas, G, grad_loss)
# if optimizer_name == 'qng_fubini_hessian':
# G = qtm.fubini_study.qng_hessian(
# u.copy(), thetas, create_vdagger_func, **kwargs)
# thetas = qtm.optimizer.qng_fubini_study(thetas, G, grad_loss)
# if optimizer_name == 'qng_fubini_study_scheduler':
# G = qtm.fubini_study.qng(
# u.copy(), thetas, create_vdagger_func, **kwargs)
# thetas = qtm.optimizer.qng_fubini_study_scheduler(thetas, G, grad_loss, i)
# if optimizer_name == 'qng_qfim':
# thetas = qtm.optimizer.qng_qfim(
# thetas, psi, grad_psi1, grad_loss)
# if optimizer_name == 'qng_adam':
# if i == 0:
# m, v = list(np.zeros(thetas.shape[0])), list(
# np.zeros(thetas.shape[0]))
# thetas = qtm.optimizer.qng_adam(
# thetas, m, v, i, psi, grad_psi1, grad_loss)
# else:
# thetas = optimizer(thetas, grad_loss)
# u_copy = create_vdagger_func(u.copy(), thetas, **kwargs)
# loss = loss_func(
# qtm.base.measure(u_copy, list(range(u_copy.num_qubits))))
# loss_values.append(loss)
# thetass.append(thetas.copy())
# if verbose == 1:
# bar.update(1)
# if verbose == 2 and i % 10 == 0:
# print("Step " + str(i) + ": " + str(loss))
# if verbose == 1:
# bar.close()

# if is_return_all_thetas:
# return thetass, loss_values
# else:
# return thetas, loss_values


def fit(u: typing.Union[qiskit.QuantumCircuit, types.FunctionType], v: typing.Union[qiskit.QuantumCircuit, types.FunctionType],
thetas: np.ndarray,
num_steps: int,
Expand Down

0 comments on commit 1096b93

Please sign in to comment.