qiskit-rigetti


Nameqiskit-rigetti JSON
Version 0.4.7 PyPI version JSON
download
home_pagehttps://github.com/rigetti/qiskit-rigetti
SummaryProvider for running Qiskit circuits on Rigetti QPUs and simulators.
upload_time2024-02-07 20:38:52
maintainer
docs_urlNone
authorRigetti Computing
requires_python>=3.8,<3.12
licenseApache-2.0
keywords qiskit quil rigetti pyquil quantum
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![Tests](https://github.com/rigetti/qiskit-rigetti/actions/workflows/test.yml/badge.svg)](https://github.com/rigetti/qiskit-rigetti/actions/workflows/test.yml)
[![Documentation Status](https://readthedocs.org/projects/qiskit-rigetti/badge/?version=latest)](https://qiskit-rigetti.readthedocs.io/en/latest/?badge=latest)
[![pypi](https://img.shields.io/pypi/v/qiskit-rigetti.svg)](https://pypi.org/project/qiskit-rigetti/)
[![Binder](https://mybinder.org/badge_logo.svg)][binder]

# Rigetti Provider for Qiskit

## Try It Out

To try out this library, you can run example notebooks in a pre-made [binder][binder]. Alternately, you can run the following to build and run the image locally:

```bash
docker build -t qiskit-tutorials .
docker run --rm -p 8888:8888 qiskit-tutorials
```

then click on the link that is displayed after the container starts up.

[binder]: https://mybinder.org/v2/gh/rigetti/qiskit-rigetti/main?filepath=examples

## Pre-requisites

1. Install [Docker](https://www.docker.com/products/docker-desktop)
1. Download [qelib1.inc](https://raw.githubusercontent.com/Qiskit/qiskit-terra/0.16.2/qiskit/qasm/libs/qelib1.inc)
1. Place `qelib1.inc` in a folder called `inc` in the project root

## Setup QVM and quilc

### Using Docker Compose

Run `docker compose up` to see service logs or `docker compose up -d` to run in the background.

### Using Docker Manually

1. Start the QVM:
   
   ```bash
   docker run --rm -it -p 5000:5000 rigetti/qvm -S
   ```

1. Start the compiler:

   ```bash
   docker run --rm -it -p 5555:5555 -v "$PWD"/inc:/inc rigetti/quilc -S -P --safe-include-directory /inc/
   ```

## Usage

Example:

```python
from qiskit import execute
from qiskit_rigetti import RigettiQCSProvider, QuilCircuit

# Get provider and backend
p = RigettiQCSProvider()
backend = p.get_simulator(num_qubits=2, noisy=True)  # or p.get_backend(name='Aspen-9')

# Create a Bell state circuit
circuit = QuilCircuit(2, 2)
circuit.h(0)
circuit.cx(0, 1)
circuit.measure([0, 1], [0, 1])

# Execute the circuit on the backend
job = execute(circuit, backend, shots=10, coupling_map=backend.coupling_map)

# Grab results from the job
result = job.result()

# Return memory and counts
memory = result.get_memory(circuit)
counts = result.get_counts(circuit)
print("Result memory:", memory)
print("Result counts:", counts)
```

### Rigetti Quantum Cloud Services (QCS)

Execution against a QPU requires a [reservation via QCS](https://docs.rigetti.com/qcs/guides/reserving-time-on-a-qpu).
For more information on using QCS, see the [QCS documentation](https://docs.rigetti.com).

## Advanced

### Lifecycle Hooks

For advanced QASM and Quil manipulation, `before_compile` and `before_execute` keyword arguments can be passed to
`RigettiQCSBackend.run()` or to Qiskit's `execute()`.

#### Pre-compilation Hooks

Any `before_compile` hooks will apply, in order, just before compilation from QASM to native Quil.
For example:

```python
...

def custom_hook_1(qasm: str) -> str:
   new_qasm = ...
   return new_qasm

def custom_hook_2(qasm: str) -> str:
   new_qasm = ...
   return new_qasm

job = execute(circuit, backend, shots=10, before_compile=[custom_hook_1, custom_hook_2])

...
```

#### Pre-execution Hooks

Any `before_execute` hooks will apply, in order, just before execution (after translation from QASM to native Quil).
For example:

```python
from pyquil import Program

...

def custom_hook_1(quil: Program) -> Program:
   new_quil = ...
   return new_quil

def custom_hook_2(quil: Program) -> Program:
   new_quil = ...
   return new_quil

job = execute(circuit, backend, shots=10, before_execute=[custom_hook_1, custom_hook_2])

...
```

> **Note**:
> 
> Only [certain forms of Quil can can be executed on a QPU](https://pyquil-docs.rigetti.com/en/stable/compiler.html?highlight=protoquil#legal-compiler-input).
> If pre-execution transformations produce a final program that is not QPU-compliant, `ensure_native_quil=True` can be
> passed to `execute()` or `RigettiQCSBackend.run()` to recompile the final Quil program to native Quil prior to
> execution. If no pre-execution hooks were supplied, this setting is ignored. If this setting is omitted, a value of
> `False` is assumed.
> 
> _Example_: Adding the Quil instruction `H 0` would result in an error if `ensure_native_quil=False` and the QPU does
> not natively implement Hadamard gates.

#### Built-in Hooks

The `hooks.pre_compilation` and `hooks.pre_execution` packages provide a number of convenient hooks:

##### `set_rewiring`

Use `set_rewiring` to provide a [rewiring directive](https://pyquil-docs.rigetti.com/en/stable/compiler.html#initial-rewiring)
to the Quil compiler. For example:

```python
from qiskit_rigetti.hooks.pre_compilation import set_rewiring

...

job = execute(circuit, backend, shots=10, before_compile=[set_rewiring("NAIVE")])

...
```

> **Note**: Rewiring directives require `quilc` version 1.25 or higher.

##### `enable_active_reset`

Use `enable_active_reset` to enable [active qubit reset](https://github.com/quil-lang/quil/blob/master/spec/Quil.md#state-reset),
an optimization that can significantly reduce the time between executions. For example:

```python
from qiskit_rigetti.hooks.pre_execution import enable_active_reset

...

job = execute(circuit, backend, shots=10, before_execute=[enable_active_reset])

...
```

## Development

> **Note**: This module is developed in Python 3.8, 3.9, and 3.10, other versions will currently fail type checking.

Dependencies are managed with [Poetry](https://python-poetry.org/) so you need to install that first. Once you've installed all dependencies (`poetry install`) and activated the virtual environment (`poetry shell`), you can use these rules from the `Makefile` to run common tasks:

1. Run tests: `make test`
1. Check style and types: `make check-all`
1. Check style only: `make check-style`
1. Check types only: `make check-types`
1. Reformat all code (to make `check-style` pass): `make format`
1. Build documentation, serve locally, and watch for changes: `make watch-docs` (requires `docs` extra: `poetry install -E docs`)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/rigetti/qiskit-rigetti",
    "name": "qiskit-rigetti",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8,<3.12",
    "maintainer_email": "",
    "keywords": "Qiskit,Quil,Rigetti,pyQuil,Quantum",
    "author": "Rigetti Computing",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/7f/c5/37e1778cc65a81f813214de5aaaf1f3d988cb34ccb2e8481cfb601974970/qiskit_rigetti-0.4.7.tar.gz",
    "platform": null,
    "description": "[![Tests](https://github.com/rigetti/qiskit-rigetti/actions/workflows/test.yml/badge.svg)](https://github.com/rigetti/qiskit-rigetti/actions/workflows/test.yml)\n[![Documentation Status](https://readthedocs.org/projects/qiskit-rigetti/badge/?version=latest)](https://qiskit-rigetti.readthedocs.io/en/latest/?badge=latest)\n[![pypi](https://img.shields.io/pypi/v/qiskit-rigetti.svg)](https://pypi.org/project/qiskit-rigetti/)\n[![Binder](https://mybinder.org/badge_logo.svg)][binder]\n\n# Rigetti Provider for Qiskit\n\n## Try It Out\n\nTo try out this library, you can run example notebooks in a pre-made [binder][binder]. Alternately, you can run the following to build and run the image locally:\n\n```bash\ndocker build -t qiskit-tutorials .\ndocker run --rm -p 8888:8888 qiskit-tutorials\n```\n\nthen click on the link that is displayed after the container starts up.\n\n[binder]: https://mybinder.org/v2/gh/rigetti/qiskit-rigetti/main?filepath=examples\n\n## Pre-requisites\n\n1. Install [Docker](https://www.docker.com/products/docker-desktop)\n1. Download [qelib1.inc](https://raw.githubusercontent.com/Qiskit/qiskit-terra/0.16.2/qiskit/qasm/libs/qelib1.inc)\n1. Place `qelib1.inc` in a folder called `inc` in the project root\n\n## Setup QVM and quilc\n\n### Using Docker Compose\n\nRun `docker compose up` to see service logs or `docker compose up -d` to run in the background.\n\n### Using Docker Manually\n\n1. Start the QVM:\n   \n   ```bash\n   docker run --rm -it -p 5000:5000 rigetti/qvm -S\n   ```\n\n1. Start the compiler:\n\n   ```bash\n   docker run --rm -it -p 5555:5555 -v \"$PWD\"/inc:/inc rigetti/quilc -S -P --safe-include-directory /inc/\n   ```\n\n## Usage\n\nExample:\n\n```python\nfrom qiskit import execute\nfrom qiskit_rigetti import RigettiQCSProvider, QuilCircuit\n\n# Get provider and backend\np = RigettiQCSProvider()\nbackend = p.get_simulator(num_qubits=2, noisy=True)  # or p.get_backend(name='Aspen-9')\n\n# Create a Bell state circuit\ncircuit = QuilCircuit(2, 2)\ncircuit.h(0)\ncircuit.cx(0, 1)\ncircuit.measure([0, 1], [0, 1])\n\n# Execute the circuit on the backend\njob = execute(circuit, backend, shots=10, coupling_map=backend.coupling_map)\n\n# Grab results from the job\nresult = job.result()\n\n# Return memory and counts\nmemory = result.get_memory(circuit)\ncounts = result.get_counts(circuit)\nprint(\"Result memory:\", memory)\nprint(\"Result counts:\", counts)\n```\n\n### Rigetti Quantum Cloud Services (QCS)\n\nExecution against a QPU requires a [reservation via QCS](https://docs.rigetti.com/qcs/guides/reserving-time-on-a-qpu).\nFor more information on using QCS, see the [QCS documentation](https://docs.rigetti.com).\n\n## Advanced\n\n### Lifecycle Hooks\n\nFor advanced QASM and Quil manipulation, `before_compile` and `before_execute` keyword arguments can be passed to\n`RigettiQCSBackend.run()` or to Qiskit's `execute()`.\n\n#### Pre-compilation Hooks\n\nAny `before_compile` hooks will apply, in order, just before compilation from QASM to native Quil.\nFor example:\n\n```python\n...\n\ndef custom_hook_1(qasm: str) -> str:\n   new_qasm = ...\n   return new_qasm\n\ndef custom_hook_2(qasm: str) -> str:\n   new_qasm = ...\n   return new_qasm\n\njob = execute(circuit, backend, shots=10, before_compile=[custom_hook_1, custom_hook_2])\n\n...\n```\n\n#### Pre-execution Hooks\n\nAny `before_execute` hooks will apply, in order, just before execution (after translation from QASM to native Quil).\nFor example:\n\n```python\nfrom pyquil import Program\n\n...\n\ndef custom_hook_1(quil: Program) -> Program:\n   new_quil = ...\n   return new_quil\n\ndef custom_hook_2(quil: Program) -> Program:\n   new_quil = ...\n   return new_quil\n\njob = execute(circuit, backend, shots=10, before_execute=[custom_hook_1, custom_hook_2])\n\n...\n```\n\n> **Note**:\n> \n> Only [certain forms of Quil can can be executed on a QPU](https://pyquil-docs.rigetti.com/en/stable/compiler.html?highlight=protoquil#legal-compiler-input).\n> If pre-execution transformations produce a final program that is not QPU-compliant, `ensure_native_quil=True` can be\n> passed to `execute()` or `RigettiQCSBackend.run()` to recompile the final Quil program to native Quil prior to\n> execution. If no pre-execution hooks were supplied, this setting is ignored. If this setting is omitted, a value of\n> `False` is assumed.\n> \n> _Example_: Adding the Quil instruction `H 0` would result in an error if `ensure_native_quil=False` and the QPU does\n> not natively implement Hadamard gates.\n\n#### Built-in Hooks\n\nThe `hooks.pre_compilation` and `hooks.pre_execution` packages provide a number of convenient hooks:\n\n##### `set_rewiring`\n\nUse `set_rewiring` to provide a [rewiring directive](https://pyquil-docs.rigetti.com/en/stable/compiler.html#initial-rewiring)\nto the Quil compiler. For example:\n\n```python\nfrom qiskit_rigetti.hooks.pre_compilation import set_rewiring\n\n...\n\njob = execute(circuit, backend, shots=10, before_compile=[set_rewiring(\"NAIVE\")])\n\n...\n```\n\n> **Note**: Rewiring directives require `quilc` version 1.25 or higher.\n\n##### `enable_active_reset`\n\nUse `enable_active_reset` to enable [active qubit reset](https://github.com/quil-lang/quil/blob/master/spec/Quil.md#state-reset),\nan optimization that can significantly reduce the time between executions. For example:\n\n```python\nfrom qiskit_rigetti.hooks.pre_execution import enable_active_reset\n\n...\n\njob = execute(circuit, backend, shots=10, before_execute=[enable_active_reset])\n\n...\n```\n\n## Development\n\n> **Note**: This module is developed in Python 3.8, 3.9, and 3.10, other versions will currently fail type checking.\n\nDependencies are managed with [Poetry](https://python-poetry.org/) so you need to install that first. Once you've installed all dependencies (`poetry install`) and activated the virtual environment (`poetry shell`), you can use these rules from the `Makefile` to run common tasks:\n\n1. Run tests: `make test`\n1. Check style and types: `make check-all`\n1. Check style only: `make check-style`\n1. Check types only: `make check-types`\n1. Reformat all code (to make `check-style` pass): `make format`\n1. Build documentation, serve locally, and watch for changes: `make watch-docs` (requires `docs` extra: `poetry install -E docs`)\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "Provider for running Qiskit circuits on Rigetti QPUs and simulators.",
    "version": "0.4.7",
    "project_urls": {
        "Documentation": "https://qiskit-rigetti.readthedocs.io",
        "Homepage": "https://github.com/rigetti/qiskit-rigetti",
        "Repository": "https://github.com/rigetti/qiskit-rigetti"
    },
    "split_keywords": [
        "qiskit",
        "quil",
        "rigetti",
        "pyquil",
        "quantum"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f7a698db78561b94ee3083c52f5667b39ada6d28606bcdd2e5914bb9194863ef",
                "md5": "8066f8748cdc02c8ecf7a41bdb6ba17a",
                "sha256": "494f6f886b762366b3e7e6a9161c1d33a9ea944001deef5c9b1ef573a267f728"
            },
            "downloads": -1,
            "filename": "qiskit_rigetti-0.4.7-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8066f8748cdc02c8ecf7a41bdb6ba17a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<3.12",
            "size": 23092,
            "upload_time": "2024-02-07T20:38:51",
            "upload_time_iso_8601": "2024-02-07T20:38:51.091588Z",
            "url": "https://files.pythonhosted.org/packages/f7/a6/98db78561b94ee3083c52f5667b39ada6d28606bcdd2e5914bb9194863ef/qiskit_rigetti-0.4.7-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7fc537e1778cc65a81f813214de5aaaf1f3d988cb34ccb2e8481cfb601974970",
                "md5": "7620589b56ad9c3069812d936cef5b82",
                "sha256": "1b0703ef4bd63a7335f1803f3a97673c6297bf68ef74fa469029a6f2a757facc"
            },
            "downloads": -1,
            "filename": "qiskit_rigetti-0.4.7.tar.gz",
            "has_sig": false,
            "md5_digest": "7620589b56ad9c3069812d936cef5b82",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<3.12",
            "size": 17491,
            "upload_time": "2024-02-07T20:38:52",
            "upload_time_iso_8601": "2024-02-07T20:38:52.771982Z",
            "url": "https://files.pythonhosted.org/packages/7f/c5/37e1778cc65a81f813214de5aaaf1f3d988cb34ccb2e8481cfb601974970/qiskit_rigetti-0.4.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-07 20:38:52",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "rigetti",
    "github_project": "qiskit-rigetti",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "qiskit-rigetti"
}
        
Elapsed time: 0.30174s