Skip to content

Commit

Permalink
Fix: Backend now binds parametric circuits before execution (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
ameyer-rigetti committed Jul 28, 2021
1 parent bc9f9f1 commit 7b9430d
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

- Removed barrier support until quilc has better compatibility. For now, barriers are omitted during compilation from OpenQASM to Quil, though they will remain in effect for Qiskit's own transpilation/optimization passes (#15)

### Fixes

- Fix errors due to unbound circuits when calling `execute()` with parametric circuits and `parameter_binds` (#16)


## [0.4.1](https://github.com/rigetti/qiskit-rigetti/releases/tag/v0.4.1)

Expand Down
4 changes: 4 additions & 0 deletions qiskit_rigetti/_qcs_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ def run(
if not isinstance(run_input, list):
run_input = [run_input]

bindings = options.get("parameter_binds") or []
if len(bindings) > 0:
run_input = [circuit.bind_parameters(binding) for circuit in run_input for binding in bindings]

run_input = [_prepare_circuit(circuit) for circuit in run_input]

if self._qc is None:
Expand Down
46 changes: 46 additions & 0 deletions tests/test_qcs_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import pytest
from qiskit import execute, QuantumCircuit, QuantumRegister, ClassicalRegister
from qiskit.providers import JobStatus
from qiskit.circuit import Parameter

from qiskit_rigetti import RigettiQCSProvider, RigettiQCSBackend

Expand Down Expand Up @@ -57,6 +58,51 @@ def test_run__multiple_circuits(backend: RigettiQCSBackend):
assert result.get_counts(1).keys() == {"000"}


def test_run__parametric_circuits(backend: RigettiQCSBackend):
t = Parameter("t")

circuit1 = QuantumCircuit(QuantumRegister(1, "q"), ClassicalRegister(1, "ro"))
circuit1.rx(t, 0)
circuit1.measure([0], [0])

circuit2 = QuantumCircuit(QuantumRegister(1, "q"), ClassicalRegister(1, "ro"))
circuit2.ry(t, 0)
circuit2.measure([0], [0])

job = execute(
[circuit1, circuit2],
backend,
shots=1000,
parameter_binds=[
{t: 1.0},
{t: 2.0},
],
)

assert job.backend() is backend
result = job.result()
assert job.status() == JobStatus.DONE

assert result.backend_name == backend.configuration().backend_name
assert len(result.results) == 4

assert result.results[0].header.name.startswith(f"{circuit1.name}-")
assert result.results[0].shots == 1000
assert result.get_counts(0).keys() == {"0", "1"}

assert result.results[1].header.name.startswith(f"{circuit1.name}-")
assert result.results[1].shots == 1000
assert result.get_counts(1).keys() == {"0", "1"}

assert result.results[2].header.name.startswith(f"{circuit2.name}-")
assert result.results[2].shots == 1000
assert result.get_counts(2).keys() == {"0", "1"}

assert result.results[3].header.name.startswith(f"{circuit2.name}-")
assert result.results[3].shots == 1000
assert result.get_counts(3).keys() == {"0", "1"}


def test_run__readout_register_not_named_ro(backend: RigettiQCSBackend):
circuit = QuantumCircuit(QuantumRegister(2, "q"), ClassicalRegister(2, "not_ro"))
circuit.measure([0, 1], [0, 1])
Expand Down

0 comments on commit 7b9430d

Please sign in to comment.