Skip to content

Commit

Permalink
Merge d18f621 into 46d1701
Browse files Browse the repository at this point in the history
  • Loading branch information
rathishcholarajan committed Jun 1, 2022
2 parents 46d1701 + d18f621 commit 748290b
Show file tree
Hide file tree
Showing 17 changed files with 495 additions and 170 deletions.
2 changes: 1 addition & 1 deletion docs/tutorials/grover_with_sampler.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@
"from qiskit_ibm_runtime import Sampler\n",
"\n",
"with Sampler(circuits=grover_circuits) as sampler:\n",
" result = sampler(circuit_indices=[0,1], shots=1000)\n",
" result = sampler(circuits=[0,1], shots=1000)\n",
" print(result)"
]
},
Expand Down
10 changes: 5 additions & 5 deletions docs/tutorials/how-to-getting-started-with-estimator.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@
"\n",
"### Run the job & print results\n",
"\n",
"Run the job, specifying your previously defined inputs and options. Use `circuit_indices`, `observable_indices`, and `parameter_values` to use a specific parameter and observable with the specified circuit.\n",
"Run the job, specifying your previously defined inputs and options. Use `circuits`, `observables`, and `parameter_values` to use a specific parameter and observable with the specified circuit.\n",
"\n",
"For example, this line `psi1_H23_result = estimator(circuit_indices=[0, 0], observable_indices=[1, 2], parameter_values=[theta1]*2)` specifies the following:\n",
"For example, this line `psi1_H23_result = estimator(circuits=[0, 0], observables=[1, 2], parameter_values=[theta1]*2)` specifies the following:\n",
"\n",
"- Return the value for using observable `H2` and parameter `theta1` with the circuit `psi1`.\n",
"- Return the value for using observable `H3` and parameter `theta1` with the circuit `psi1`."
Expand Down Expand Up @@ -117,15 +117,15 @@
" theta3 = [1, 2, 3, 4, 5, 6]\n",
"\n",
" # calculate [ <psi1(theta1)|H1|psi1(theta1)> ]\n",
" psi1_H1_result = estimator(circuit_indices=[0], observable_indices=[0], parameter_values=[theta1])\n",
" psi1_H1_result = estimator(circuits=[0], observables=[0], parameter_values=[theta1])\n",
" print(psi1_H1_result)\n",
"\n",
" # calculate [ <psi1(theta1)|H2|psi1(theta1)>, <psi1(theta1)|H3|psi1(theta1)> ]\n",
" psi1_H23_result = estimator(circuit_indices=[0, 0], observable_indices=[1, 2], parameter_values=[theta1]*2)\n",
" psi1_H23_result = estimator(circuits=[0, 0], observables=[1, 2], parameter_values=[theta1]*2)\n",
" print(psi1_H23_result)\n",
"\n",
" # calculate [ <psi2(theta2)|H2|psi2(theta2)> ]\n",
" # Note that you don't need to specify the labels \"circuit_indices\", \"observable_indices\", or \"parameter_values\", as long as they are specified in that order.\n",
" # Note that you don't need to specify the labels \"circuits\", \"observables\", or \"parameter_values\", as long as they are specified in that order.\n",
" psi2_H2_result = estimator([1], [1], [theta2])\n",
" print(psi2_H2_result)\n",
"\n",
Expand Down
14 changes: 7 additions & 7 deletions docs/tutorials/how-to-getting-started-with-sampler.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@
"\n",
"Run the job, specifying your previously defined inputs and options. In this simple example, there is only one circuit and it does not have parameters.\n",
"\n",
"In each call, you will use `circuit_indices` to specify which circuit to run and, if applicable, `parameter_values` specifies which parameter to use with the specified circuit.\n",
"In each call, you will use `circuits` to specify which circuit to run and, if applicable, `parameter_values` specifies which parameter to use with the specified circuit.\n",
"\n",
"In this example, we specified one circuit, `circuits=bell`, and we asked for the result for running the first (and only) circuit: `circuit_indices=[0]`.\n",
"In this example, we specified one circuit, `circuits=bell`, and we asked for the result for running the first (and only) circuit: `circuits=[0]`.\n",
"\n",
"As you will see in later examples, if we had specified multiple circuits, such as `circuits=[pqc, pqc2]`, you could specify `circuit_indices=[1]` to run the `pqc2` circuit."
"As you will see in later examples, if we had specified multiple circuits, such as `circuits=[pqc, pqc2]`, you could specify `circuits=[1]` to run the `pqc2` circuit."
]
},
{
Expand All @@ -98,7 +98,7 @@
"source": [
"# executes a Bell circuit\n",
"with Sampler(circuits=bell, service=service, options={ \"backend\": \"ibmq_qasm_simulator\" }) as sampler:\n",
" result = sampler(circuit_indices=[0], shots=1024)\n",
" result = sampler(circuits=[0], shots=1024)\n",
" print(result)"
]
},
Expand Down Expand Up @@ -139,7 +139,7 @@
"\n",
"# executes three Bell circuits\n",
"with Sampler(circuits=[bell]*3, service=service, options={ \"backend\": \"ibmq_qasm_simulator\" }) as sampler:\n",
" result = sampler(circuit_indices=[0, 1, 2])\n",
" result = sampler(circuits=[0, 1, 2])\n",
" print(result)"
]
},
Expand All @@ -150,7 +150,7 @@
"source": [
"## Multiple parameterized circuits example\n",
"\n",
"In this example, we run multiple parameterized circuits. When it is run, this line `result = sampler(circuit_indices=[0, 0, 1], parameter_values=[theta1, theta2, theta3])` specifies which parameter to send to each circuit. \n",
"In this example, we run multiple parameterized circuits. When it is run, this line `result = sampler(circuits=[0, 0, 1], parameter_values=[theta1, theta2, theta3])` specifies which parameter to send to each circuit. \n",
"\n",
"In our example, the parameter labeled `theta` is sent to the first circuit, `theta2` is sent to the first circuit, and `theta3` is sent to the second circuit."
]
Expand Down Expand Up @@ -187,7 +187,7 @@
"theta3 = [0, 1, 2, 3, 4, 5, 6, 7]\n",
"\n",
"with Sampler(circuits=[pqc, pqc2], service=service, options={ \"backend\": \"ibmq_qasm_simulator\" }) as sampler:\n",
" result = sampler(circuit_indices=[0, 0, 1], parameter_values=[theta1, theta2, theta3])\n",
" result = sampler(circuits=[0, 0, 1], parameter_values=[theta1, theta2, theta3])\n",
" print(result)"
]
},
Expand Down
4 changes: 2 additions & 2 deletions docs/tutorials/sea_with_sampler.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@
"id": "6a0ede58",
"metadata": {},
"source": [
"In the `Sampler` class, we pass the list of circuits and parameter keys in the constructor. When calling the `sampler`, we specify a list of `circuit_indices` pointing to the circuits desired to be run (which was passed to the constructor), in this case, the index `0` `num_pts` times."
"In the `Sampler` class, we pass the list of circuits and parameter keys in the constructor. When calling the `sampler`, we specify a list of `circuits` pointing to the circuits desired to be run (which was passed to the constructor), in this case, the index `0` `num_pts` times."
]
},
{
Expand All @@ -220,7 +220,7 @@
" options=options,\n",
" skip_transpilation=True) as sampler:\n",
" result = sampler(\n",
" circuit_indices=[0]*num_pts, \n",
" circuits=[0]*num_pts, \n",
" parameter_values=param_vals,\n",
" shots=1e5\n",
" )"
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/user-transpiled-circuits.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,7 @@
" options={'backend': backend},\n",
" skip_transpilation=True) as sampler:\n",
" result = sampler(\n",
" circuit_indices=[0,1,2], # sample all three circuits\n",
" circuits=[0,1,2], # sample all three circuits\n",
" shots=8000\n",
" )"
]
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/vqe_with_estimator.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
") as estimator:\n",
" def evaluate_expectation(x):\n",
" x = list(x)\n",
" results = estimator(circuit_indices=[0], observable_indices=[0], parameter_values=[x]).values[0]\n",
" results = estimator(circuits=[0], observables=[0], parameter_values=[x]).values[0]\n",
" return np.real(results)\n",
" \n",
" def callback(fx):\n",
Expand Down
25 changes: 16 additions & 9 deletions qiskit_ibm_runtime/estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,19 @@ class Estimator(BaseEstimator):
The returned instance can be called repeatedly with the following parameters to
estimate expectation values.
* circuit_indices: A list of circuit indices.
* circuits: a (parameterized) :class:`~qiskit.circuit.QuantumCircuit` or
a list of (parameterized) :class:`~qiskit.circuit.QuantumCircuit` or
a list of circuit indices.
* observable_indices: A list of observable indices.
* observables: a list of :class:`~qiskit.quantum_info.SparsePauliOp` or
a list of observable indices.
* parameter_values: An optional list of concrete parameters to be bound.
* circuit_indices: (DEPRECATED) A list of circuit indices.
* observable_indices: (DEPRECATED) A list of observable indices.
All the above lists should be of the same length.
Example::
Expand Down Expand Up @@ -197,10 +204,10 @@ def __init__(
options=options,
)

def __call__(
def _call(
self,
circuit_indices: Sequence[int],
observable_indices: Sequence[int],
circuits: Sequence[int],
observables: Sequence[int],
parameter_values: Optional[
Union[Sequence[float], Sequence[Sequence[float]]]
] = None,
Expand All @@ -209,17 +216,17 @@ def __call__(
"""Estimates expectation values for given inputs in a runtime session.
Args:
circuit_indices: A list of circuit indices.
observable_indices: A list of observable indices.
circuits: A list of circuit indices.
observables: A list of observable indices.
parameter_values: An optional list of concrete parameters to be bound.
**run_options: A collection of kwargs passed to `backend.run()`.
Returns:
An instance of :class:`qiskit.primitives.EstimatorResult`.
"""
self._session.write(
circuit_indices=circuit_indices,
observable_indices=observable_indices,
circuit_indices=circuits,
observable_indices=observables,
parameter_values=parameter_values,
run_options=run_options,
)
Expand Down
Loading

0 comments on commit 748290b

Please sign in to comment.