Skip to content

Commit 3c2e509

Browse files
author
Antonio Martinez
authored
Update deprecated Cirq names (wavefunction -> state_vector) (#403)
* updated some wavefunction to state_vector * removed remaining instances of wavefunction, replaced with state_vector * changed final_state to final_state_vector * formatting * formatting
1 parent 1f3f532 commit 3c2e509

18 files changed

+64
-63
lines changed

docs/tutorials/gradients.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,8 @@
233233
" \"\"\"Compute ⟨Y(alpha)| `op` | Y(alpha)⟩\"\"\"\n",
234234
" params = {'alpha': alpha}\n",
235235
" sim = cirq.Simulator()\n",
236-
" final_state = sim.simulate(my_circuit, params).final_state\n",
237-
" return op.expectation_from_wavefunction(final_state, {qubit: 0}).real\n",
236+
" final_state_vector = sim.simulate(my_circuit, params).final_state_vector\n",
237+
" return op.expectation_from_state_vector(final_state_vector, {qubit: 0}).real\n",
238238
"\n",
239239
"\n",
240240
"my_alpha = 0.3\n",

docs/tutorials/hello_many_worlds.ipynb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@
246246
"source": [
247247
"# Calculate a state vector with a=0.5 and b=-0.5.\n",
248248
"resolver = cirq.ParamResolver({a: 0.5, b: -0.5})\n",
249-
"output_state_vector = cirq.Simulator().simulate(circuit, resolver).final_state\n",
249+
"output_state_vector = cirq.Simulator().simulate(circuit, resolver).final_state_vector\n",
250250
"output_state_vector"
251251
]
252252
},
@@ -275,7 +275,7 @@
275275
"\n",
276276
"qubit_map={q0: 0, q1: 1}\n",
277277
"\n",
278-
"z0.expectation_from_wavefunction(output_state_vector, qubit_map).real"
278+
"z0.expectation_from_state_vector(output_state_vector, qubit_map).real"
279279
]
280280
},
281281
{
@@ -290,7 +290,7 @@
290290
"source": [
291291
"z0x1 = 0.5 * z0 + cirq.X(q1)\n",
292292
"\n",
293-
"z0x1.expectation_from_wavefunction(output_state_vector, qubit_map).real"
293+
"z0x1.expectation_from_state_vector(output_state_vector, qubit_map).real"
294294
]
295295
},
296296
{
@@ -402,9 +402,9 @@
402402
"\n",
403403
"for vals in batch_vals:\n",
404404
" resolver = cirq.ParamResolver({a: vals[0], b: vals[1]})\n",
405-
" final_state = cirq_simulator.simulate(circuit, resolver).final_state\n",
405+
" final_state_vector = cirq_simulator.simulate(circuit, resolver).final_state_vector\n",
406406
" cirq_results.append(\n",
407-
" [z0.expectation_from_wavefunction(final_state, {\n",
407+
" [z0.expectation_from_state_vector(final_state_vector, {\n",
408408
" q0: 0,\n",
409409
" q1: 1\n",
410410
" }).real])\n",
@@ -919,8 +919,8 @@
919919
" state = cirq_simulator.simulate(\n",
920920
" full_circuit,\n",
921921
" {s:v for (s,v) in zip(control_params, params_to_prepare_output[index])}\n",
922-
" ).final_state\n",
923-
" expectation = z0.expectation_from_wavefunction(state, {qubit: 0}).real\n",
922+
" ).final_state_vector\n",
923+
" expectation = z0.expectation_from_state_vector(state, {qubit: 0}).real\n",
924924
" print(f'For a desired output (expectation) of {desired_values[index]} with'\n",
925925
" f' noisy preparation, the controller\\nnetwork found the following '\n",
926926
" f'values for theta: {params_to_prepare_output[index]}\\nWhich gives an'\n",

tensorflow_quantum/core/ops/batch_util.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def _setup_dict(array_view, view_shape, simulator, post_process):
211211

212212

213213
def _state_worker_func(indices, programs, params):
214-
"""Compute the wavefunction for each program in indices."""
214+
"""Compute the state vector for each program in indices."""
215215
x_np = _convert_complex_view_to_np(INFO_DICT['arr'], INFO_DICT['shape'])
216216
simulator = INFO_DICT['sim']
217217

@@ -243,7 +243,7 @@ def _analytical_expectation_worker_func(indices, programs, params, ops):
243243
continue
244244

245245
if old_batch_index != batch_index:
246-
# must compute a new wavefunction.
246+
# must compute a new state vector.
247247
qubit_oder = dict(
248248
zip(sorted(programs[batch_index].all_qubits()),
249249
list(range(len(programs[batch_index].all_qubits())))))
@@ -349,7 +349,7 @@ def batch_calculate_state(circuits, param_resolvers, simulator):
349349
`cirq.ParamResolver` in `param_resolvers` was used to resolve any symbols
350350
in it. If simulator is a `cirq.DensityMatrixSimulator` this final state will
351351
be a density matrix, if simulator is a `cirq.Simulator` this final state
352-
will be a wavefunction. More specifically for a given `i`
352+
will be a state vector. More specifically for a given `i`
353353
`batch_calculate_state` will use `param_resolvers[i]` to resolve the symbols
354354
in `circuits[i]` and then place the final state in the return list at index
355355
`i`.
@@ -445,8 +445,8 @@ def batch_calculate_expectation(circuits, param_resolvers, ops, simulator):
445445
state.final_density_matrix, order) for x in op).real
446446
elif isinstance(simulator, cirq.Simulator):
447447
post_process = \
448-
lambda op, state, order: op.expectation_from_wavefunction(
449-
state.final_state, order).real
448+
lambda op, state, order: op.expectation_from_state_vector(
449+
state.final_state_vector, order).real
450450
else:
451451
raise TypeError('Simulator {} is not supported by '
452452
'batch_calculate_expectation.'.format(type(simulator)))
@@ -620,7 +620,7 @@ def batch_sample(circuits, param_resolvers, n_samples, simulator):
620620
repetitions=n_samples)
621621
elif isinstance(simulator, cirq.Simulator):
622622
post_process = lambda state, size, n_samples: cirq.sample_state_vector(
623-
state.final_state, list(range(size)), repetitions=n_samples)
623+
state.final_state_vector, list(range(size)), repetitions=n_samples)
624624
else:
625625
raise TypeError('Simulator {} is not supported by batch_sample.'.format(
626626
type(simulator)))

tensorflow_quantum/core/ops/batch_util_test.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def _get_mixed_batch(qubits, symbols, size):
3737

3838
def _pad_state(sim, state, n):
3939
if isinstance(sim, cirq.Simulator):
40-
state = state.final_state
40+
state = state.final_state_vector
4141
if isinstance(sim, cirq.DensityMatrixSimulator):
4242
state = state.final_density_matrix
4343
return np.pad(state, (0, (1 << n) - state.shape[-1]),
@@ -47,9 +47,10 @@ def _pad_state(sim, state, n):
4747

4848
def _expectation_helper(sim, circuit, params, op):
4949
if isinstance(sim, cirq.Simulator):
50-
state = sim.simulate(circuit, params).final_state.astype(np.complex128)
50+
state = sim.simulate(circuit,
51+
params).final_state_vector.astype(np.complex128)
5152
return [
52-
op.expectation_from_wavefunction(
53+
op.expectation_from_state_vector(
5354
state,
5455
dict(
5556
zip(sorted(circuit.all_qubits()),
@@ -73,7 +74,7 @@ def _expectation_helper(sim, circuit, params, op):
7374

7475
def _sample_helper(sim, state, n_qubits, n_samples):
7576
if isinstance(sim, cirq.Simulator):
76-
return cirq.sample_state_vector(state.final_state,
77+
return cirq.sample_state_vector(state.final_state_vector,
7778
list(range(n_qubits)),
7879
repetitions=n_samples)
7980
if isinstance(sim, cirq.DensityMatrixSimulator):
@@ -92,8 +93,8 @@ class BatchUtilTest(tf.test.TestCase, parameterized.TestCase):
9293
}, {
9394
'sim': cirq.Simulator()
9495
}])
95-
def test_batch_simulate_state(self, sim):
96-
"""Test variable sized wavefunction output."""
96+
def test_batch_simulate_state_vector(self, sim):
97+
"""Test variable sized state vector output."""
9798
circuit_batch, resolver_batch = _get_mixed_batch(
9899
cirq.GridQubit.rect(1, N_QUBITS), SYMBOLS, BATCH_SIZE)
99100
results = batch_util.batch_calculate_state(circuit_batch,

tensorflow_quantum/core/ops/circuit_execution_ops.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from tensorflow_quantum.python import quantum_context
2323

2424

25-
class TFQWavefunctionSimulator(enum.Enum):
25+
class TFQStateVectorSimulator(enum.Enum):
2626
"""Enum to make specifying TFQ simulators user-friendly."""
2727
expectation = tfq_simulate_ops.tfq_simulate_expectation
2828
samples = tfq_simulate_ops.tfq_simulate_samples
@@ -120,7 +120,7 @@ def get_expectation_op(
120120

121121
op = None
122122
if backend is None:
123-
op = TFQWavefunctionSimulator.expectation
123+
op = TFQStateVectorSimulator.expectation
124124

125125
if isinstance(backend, cirq.SimulatesFinalState):
126126
op = cirq_ops._get_cirq_analytical_expectation(backend)
@@ -216,7 +216,7 @@ def get_sampling_op(
216216

217217
op = None
218218
if backend is None:
219-
op = TFQWavefunctionSimulator.samples
219+
op = TFQStateVectorSimulator.samples
220220

221221
if isinstance(backend, cirq.Sampler):
222222
op = cirq_ops._get_cirq_samples(backend)
@@ -269,7 +269,7 @@ def get_state_op(
269269
backend: Optional Python `object` that specifies what backend this op
270270
should use when evaluating circuits. Can be any
271271
`cirq.SimulatesFinalState`. If not provided, the default C++
272-
wavefunction simulator will be used.
272+
state vector simulator will be used.
273273
quantum_concurrent: Optional Python `bool`. True indicates that the
274274
returned op should not block graph level parallelism on itself when
275275
executing. False indicates that graph level parallelism on itself
@@ -305,7 +305,7 @@ def get_state_op(
305305

306306
op = None
307307
if backend is None:
308-
op = TFQWavefunctionSimulator.state
308+
op = TFQStateVectorSimulator.state
309309

310310
if isinstance(backend, (cirq.SimulatesFinalState)):
311311
op = cirq_ops._get_cirq_simulate_state(backend)
@@ -416,7 +416,7 @@ def get_sampled_expectation_op(
416416

417417
op = None
418418
if backend is None:
419-
op = TFQWavefunctionSimulator.sampled_expectation
419+
op = TFQStateVectorSimulator.sampled_expectation
420420

421421
if isinstance(backend, cirq.Sampler):
422422
op = cirq_ops._get_cirq_sampled_expectation(backend)

tensorflow_quantum/core/ops/cirq_ops_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,10 @@ def test_simulate_state_output_padding(self, op_and_sim, all_n_qubits):
281281
blank_state[:dm.shape[0], :dm.shape[1]] = dm
282282
manual_padded_results.append(blank_state)
283283

284-
# wavefunctions should be zero everywhere to the right of the states
284+
# state vectors should be zero everywhere to the right of the states
285285
# present in this system
286286
elif isinstance(result, cirq.StateVectorTrialResult):
287-
wf = result.final_state
287+
wf = result.final_state_vector
288288
blank_state = np.ones(
289289
(2**max(all_n_qubits)), dtype=np.complex64) * -2
290290
blank_state[:wf.shape[0]] = wf

tensorflow_quantum/core/ops/math_ops/inner_product_op_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,9 @@ def test_correctness_with_symbols(self, n_qubits, batch_size,
245245
for i in range(batch_size):
246246
final_circuit = cirq.resolve_parameters(circuit_batch[i],
247247
resolver_batch[i])
248-
final_wf = cirq.final_wavefunction(final_circuit)
248+
final_wf = cirq.final_state_vector(final_circuit)
249249
for j in range(inner_dim_size):
250-
internal_wf = cirq.final_wavefunction(other_batch[i][j])
250+
internal_wf = cirq.final_state_vector(other_batch[i][j])
251251
out_arr[i][j] = np.vdot(final_wf, internal_wf)
252252

253253
self.assertAllClose(out, out_arr)
@@ -292,9 +292,9 @@ def test_correctness_without_symbols(self, n_qubits, batch_size,
292292

293293
out_arr = np.empty((batch_size, inner_dim_size), dtype=np.complex64)
294294
for i in range(batch_size):
295-
final_wf = cirq.final_wavefunction(circuit_batch[i])
295+
final_wf = cirq.final_state_vector(circuit_batch[i])
296296
for j in range(inner_dim_size):
297-
internal_wf = cirq.final_wavefunction(other_batch[i][j])
297+
internal_wf = cirq.final_state_vector(other_batch[i][j])
298298
out_arr[i][j] = np.vdot(final_wf, internal_wf)
299299

300300
self.assertAllClose(out, out_arr)

tensorflow_quantum/core/ops/math_ops/tfq_inner_product.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ class TfqInnerProductOp : public tensorflow::OpKernel {
162162
State sv = StateSpace(largest_nq, tfq_for).CreateState();
163163
State scratch = StateSpace(largest_nq, tfq_for).CreateState();
164164

165-
// Simulate programs one by one. Parallelizing over wavefunctions
165+
// Simulate programs one by one. Parallelizing over state vectors
166166
// we no longer parallelize over circuits. Each time we encounter a
167167
// a larger circuit we will grow the Statevector as necessary.
168168
for (int i = 0; i < fused_circuits.size(); i++) {
@@ -239,8 +239,8 @@ class TfqInnerProductOp : public tensorflow::OpKernel {
239239
}
240240

241241
if (cur_batch_index != old_batch_index) {
242-
// We've run into a new wavefunction we must compute.
243-
// Only compute a new wavefunction when we have to.
242+
// We've run into a new state vector we must compute.
243+
// Only compute a new state vector when we have to.
244244
if (nq > largest_nq) {
245245
sv = ss.CreateState();
246246
scratch = ss.CreateState();

tensorflow_quantum/core/ops/tfq_calculate_unitary_op.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class TfqCalculateUnitaryOp : public tensorflow::OpKernel {
108108
int largest_nq = 1;
109109
Unitary u = UnitarySpace(largest_nq, tfq_for).CreateUnitary();
110110

111-
// Simulate programs one by one. Parallelizing over wavefunctions
111+
// Simulate programs one by one. Parallelizing over state vectors
112112
// we no longer parallelize over circuits. Each time we encounter a
113113
// a larger circuit we will grow the unitary as nescessary.
114114
for (int i = 0; i < fused_circuits.size(); i++) {

tensorflow_quantum/core/ops/tfq_simulate_expectation_op.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class TfqSimulateExpectationOp : public tensorflow::OpKernel {
134134
State sv = StateSpace(largest_nq, tfq_for).CreateState();
135135
State scratch = StateSpace(largest_nq, tfq_for).CreateState();
136136

137-
// Simulate programs one by one. Parallelizing over wavefunctions
137+
// Simulate programs one by one. Parallelizing over state vectors
138138
// we no longer parallelize over circuits. Each time we encounter a
139139
// a larger circuit we will grow the Statevector as necessary.
140140
for (int i = 0; i < fused_circuits.size(); i++) {
@@ -205,8 +205,8 @@ class TfqSimulateExpectationOp : public tensorflow::OpKernel {
205205
}
206206

207207
if (cur_batch_index != old_batch_index) {
208-
// We've run into a new wavefunction we must compute.
209-
// Only compute a new wavefunction when we have to.
208+
// We've run into a new state vector we must compute.
209+
// Only compute a new state vector when we have to.
210210
if (nq > largest_nq) {
211211
sv = ss.CreateState();
212212
scratch = ss.CreateState();

0 commit comments

Comments
 (0)