Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use simpler argument style for V2 Sampler #1122

Merged
merged 2 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions docs/api/migration-guides/v2-primitives.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,15 @@ Sampler V2 example that uses shots in `run()`:

```python
# Sample two circuits at 128 shots each.
sampler.run([(circuit1,), (circuit2,)], shots=128)
sampler.run([circuit1, circuit2], shots=128)

# Sample two circuits at different amounts of shots. The "None"s are necessary
# as placeholders
# Sample two circuits at different amounts of shots.
# The "None"s are necessary as placeholders
# for the lack of parameter values in this example.
sampler.run([(circuit1, None, 123), (circuit2, None, 456)])
sampler.run([
(circuit1, None, 123),
(circuit2, None, 456),
])
```

#### Output
Expand Down Expand Up @@ -226,7 +229,7 @@ pm = generate_preset_pass_manager(backend=backend, optimization_level=1)
isa_circuit = pm.run(circuit)

sampler = Sampler(backend)
job = sampler.run([(isa_circuit,)])
job = sampler.run([isa_circuit])
result = job.result()
# Get results for the first (and only) PUB
pub_result = result[0]
Expand Down Expand Up @@ -886,7 +889,7 @@ pm = generate_preset_pass_manager(backend=backend, optimization_level=1)
isa_circuit = pm.run(circuit)

sampler = Sampler(backend)
job = sampler.run([(isa_circuit,)])
job = sampler.run([isa_circuit])
result = job.result()
```
</TabItem>
Expand Down Expand Up @@ -1109,8 +1112,8 @@ backend = service.least_busy(operational=True, simulator=False, min_num_qubits=1

with Session(service=service, backend=backend) as session:
sampler = Sampler(session=session)
job = sampler.run([(isa_circuit)])
another_job = sampler.run([(another_isa_circuit)])
job = sampler.run([isa_circuit])
another_job = sampler.run([another_isa_circuit])
result = job.result()
another_result = another_job.result()

Expand Down
2 changes: 1 addition & 1 deletion docs/build/bit-ordering.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ decimal integer `2` (measured with probability `1.0`).
from qiskit.primitives import Samplerv2 as Sampler
qc.measure_all()

job = sampler.run([(qc)])
job = sampler.run([qc])
result = job.result()
print(f" > Counts: {result[0].data.meas.get_counts()}")
```
Expand Down
4 changes: 2 additions & 2 deletions docs/run/advanced-runtime-options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ You can pass in options by using the `run()` method. This overwrites the options
In V2, the only options you can pass to `run()` are options defined in the interface. That is, `shots` for Sampler and `precision` for Estimator.
```python
# Sample two circuits at 128 shots each.
sampler.run([(circuit1,), (circuit2,)], shots=128)
sampler.run([circuit1, circuit2], shots=128)
```

</TabItem>
Expand Down Expand Up @@ -162,7 +162,7 @@ sampler.options.default_shots=2000
sampler.options.update(default_shots=1024, dynamical_decoupling={"sequence_type": "XpXm"})

# Sample two circuits at 128 shots each.
sampler.run([(circuit1,), (circuit2,)], shots=128)
sampler.run([circuit1, circuit2], shots=128)
```
</TabItem>

Expand Down
2 changes: 1 addition & 1 deletion docs/run/estimate-job-run-time.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ isa_circuit = pm.run(qc)
sampler = Sampler(backend)

# Submit the circuit to the sampler
job = sampler.run([(isa_circuit,)])
job = sampler.run([isa_circuit])

print(job.usage_estimation)
```
Expand Down
6 changes: 3 additions & 3 deletions docs/run/primitives-examples.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ pm = generate_preset_pass_manager(backend=backend, optimization_level=1)
isa_circuit = pm.run(circuit)

sampler = Sampler(backend)
job = sampler.run([(isa_circuit,)])
job = sampler.run([isa_circuit])
result = job.result()
```
</TabItem>
Expand Down Expand Up @@ -627,8 +627,8 @@ another_isa_circuit = pm.run(another_circuit)

with Session(service=service, backend=backend) as session:
sampler = Sampler(session=session)
job = sampler.run([(isa_circuit)])
another_job = sampler.run([(another_isa_circuit)])
job = sampler.run([isa_circuit])
another_job = sampler.run([another_isa_circuit])
result = job.result()
another_result = another_job.result()

Expand Down
2 changes: 1 addition & 1 deletion docs/run/primitives-get-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ For Sampler V2, the circuit and optional parameter value sets are input as *prim
<TabItem value="SamplerV2" label="Sampler V2">

```python
job = sampler.run([(isa_circuit)])
job = sampler.run([isa_circuit])
print(f">>> Job ID: {job.job_id()}")
print(f">>> Job Status: {job.status()}")
```
Expand Down
5 changes: 4 additions & 1 deletion docs/run/primitives.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,10 @@ sampler.run([circuit1, circuit2, ...],[observable1, observable2, ...],[param_val
Example:

```python
sampler.run([(circuit1, param_values1, shots1),(circuit2, param_values2, shots_2) ])
sampler.run([
(circuit1, param_values1, shots1),
(circuit2, param_values2, shots_2),
])
```

## Estimator
Expand Down
2 changes: 1 addition & 1 deletion docs/run/quantum-serverless.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ target_circuit = selector.optimized_circuit

# Step 3: Execute the target circuit
sampler = Sampler(backend=backend, options={"default_shots": 1024})
job = sampler.run([(target_circuit,)])
job = sampler.run([target_circuit])
result = job.result()

# Step 4: Postprocess the results
Expand Down
2 changes: 1 addition & 1 deletion docs/run/run-jobs-in-session.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ with Session(backend=backend):
sampler = Sampler()
estimator = Estimator()

job = sampler.run([(sampler_circuit,)])
job = sampler.run([sampler_circuit])
result = job.result()
print(f" > Counts: {result[0].data.meas.get_counts()}")

Expand Down
4 changes: 2 additions & 2 deletions docs/start/setup-channel.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ service = QiskitRuntimeService()
backend = service.backend("ibmq_qasm_simulator")

sampler = Sampler(backend)
job = sampler.run([(example_circuit,)])
job = sampler.run([example_circuit])
print(f"job id: {job.job_id()}")
result = job.result()
print(result)
Expand Down Expand Up @@ -173,7 +173,7 @@ print(result)
service = QiskitRuntimeService()
backend = service.backend("ibmq_qasm_simulator")
sampler = Sampler(backend)
job = sampler.run([(example_circuit,)])
job = sampler.run([example_circuit])
print(f"job id: {job.job_id()}")
result = job.result()
print(result)
Expand Down
Loading