Skip to content

Commit

Permalink
Replace bind_parameters with assign_parameters (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
ElePT authored Sep 13, 2023
1 parent a387f3e commit 0c7d25c
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions docs/tutorials/10_pvqd.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@
"source": [
"from qiskit.quantum_info import Statevector\n",
"\n",
"initial_state = Statevector(ansatz.bind_parameters(initial_parameters))\n",
"initial_state = Statevector(ansatz.assign_parameters(initial_parameters))\n",
"exact_times, exact_energies, exact_magnetizations = exact(\n",
" final_time, 0.01, hamiltonian, initial_state\n",
")"
Expand Down Expand Up @@ -1012,4 +1012,4 @@
},
"nbformat": 4,
"nbformat_minor": 4
}
}
2 changes: 1 addition & 1 deletion qiskit_algorithms/eigensolvers/vqd.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def compute_eigenvalues(
initial_point = validate_initial_point(initial_points[step - 1], self.ansatz)

if step > 1:
prev_states.append(self.ansatz.bind_parameters(result.optimal_points[-1]))
prev_states.append(self.ansatz.assign_parameters(result.optimal_points[-1]))

self._eval_count = 0
energy_evaluation = self._get_evaluate_energy(
Expand Down
2 changes: 1 addition & 1 deletion qiskit_algorithms/gradients/reverse/bind.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def bind(
"""Bind parameters in a circuit (or list of circuits).
This method also allows passing parameter binds to parameters that are not in the circuit,
and thereby differs to :meth:`.QuantumCircuit.bind_parameters`.
and thereby differs to :meth:`.QuantumCircuit.assign_parameters`.
Args:
circuits: Input circuit(s).
Expand Down
2 changes: 1 addition & 1 deletion qiskit_algorithms/optimizers/spsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class SPSA(Optimizer):
initial_point = np.random.random(ansatz.num_parameters)
def loss(x):
bound = ansatz.bind_parameters(x)
bound = ansatz.assign_parameters(x)
return np.real((StateFn(observable, is_measurement=True) @ StateFn(bound)).eval())
spsa = SPSA(maxiter=300)
Expand Down
4 changes: 2 additions & 2 deletions qiskit_algorithms/time_evolvers/pvqd/pvqd.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def get_loss(
self._validate_setup(skip={"optimizer"})

# use Trotterization to evolve the current state
trotterized = ansatz.bind_parameters(current_parameters)
trotterized = ansatz.assign_parameters(current_parameters)

evolution_gate = PauliEvolutionGate(hamiltonian, time=dt, synthesis=self.evolution)

Expand Down Expand Up @@ -389,7 +389,7 @@ def evolve(self, evolution_problem: TimeEvolutionProblem) -> TimeEvolutionResult
if observables is not None:
observable_values.append(evaluate_observables(next_parameters))

evolved_state = self.ansatz.bind_parameters(parameters[-1])
evolved_state = self.ansatz.assign_parameters(parameters[-1])

result = PVQDResult(
evolved_state=evolved_state,
Expand Down
2 changes: 1 addition & 1 deletion test/optimizers/test_gradient_descent.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_pauli_two_design(self):
)

def objective_pauli(x):
bound_circ = circuit.bind_parameters(dict(zip(parameters, x)))
bound_circ = circuit.assign_parameters(dict(zip(parameters, x)))
return Statevector(bound_circ).expectation_value(obs).real

optimizer = GradientDescent(maxiter=100, learning_rate=0.1, perturbation=0.1)
Expand Down
2 changes: 1 addition & 1 deletion test/optimizers/test_spsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_pauli_two_design(self, method):
)

def objective(x):
bound_circ = circuit.bind_parameters(dict(zip(parameters, x)))
bound_circ = circuit.assign_parameters(dict(zip(parameters, x)))
return Statevector(bound_circ).expectation_value(obs).real

settings = {"maxiter": 100, "blocking": True, "allowed_increase": 0}
Expand Down
2 changes: 1 addition & 1 deletion test/time_evolvers/variational/test_var_qrte.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def expected_state(time):
result = varqrte.evolve(evolution_problem)

final_parameters = result.parameter_values[-1]
final_state = Statevector(circuit.bind_parameters(final_parameters)).to_dict()
final_state = Statevector(circuit.assign_parameters(final_parameters)).to_dict()
final_expected_state = expected_state(final_time)

for key, expected_value in final_state.items():
Expand Down

0 comments on commit 0c7d25c

Please sign in to comment.