Skip to content

Commit

Permalink
Merge pull request #49 from zapatacomputing/dev
Browse files Browse the repository at this point in the history
Merge dev to master
  • Loading branch information
max-radin authored Oct 20, 2021
2 parents 625ff95 + 2cabe1e commit 6584b15
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

[![codecov](https://codecov.io/gh/zapatacomputing/qe-forest/branch/master/graph/badge.svg?token=GI5NIW5TGI)](https://codecov.io/gh/zapatacomputing/qe-forest)

`qe-forest` is a Python module that exposes Rigetti's [Quantum Virtual Machine (QVM)](https://github.com/rigetti/qvm) simulator and [QUILC compiler](https://github.com/rigetti/quilc) as a [`z-quantum-core`](https://github.com/zapatacomputing/z-quantum-core/blob/master/src/python/zquantum/core/interfaces/backend.py) `QuantumSimulator`.
An Orquestra Quantum Engine Resource for Rigetti's Forest

## Overview

`qe-forest` is a Python module that exposes Rigetti's [Quantum Virtual Machine (QVM)](https://github.com/rigetti/qvm) simulator and [QUILC compiler](https://github.com/rigetti/quilc) as a [`z-quantum-core`](https://github.com/zapatacomputing/z-quantum-core/blob/master/src/python/zquantum/core/interfaces/backend.py) `QuantumSimulator`. In addition, it also provides converters that allow switching between [PyQuil](https://github.com/rigetti/pyquil) circuits and those of `z-quantum-core`.
It can be used directly in Python or in an [Orquestra](https://www.orquestra.io) workflow.
For more details, see the [Orquestra Pyquil integration docs](http://docs.orquestra.io/other-resources/framework-integrations/pyquil/).

For more information regarding Orquestra and resources, please refer to the [Orquestra documentation](https://www.orquestra.io/docs).

## Development and contribution

You can find the development guidelines in the [`z-quantum-core` repository](https://github.com/zapatacomputing/z-quantum-core).
19 changes: 14 additions & 5 deletions src/python/qeforest/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

import numpy as np
from pyquil.api import WavefunctionSimulator, get_qc
from qeforest.conversions import export_to_pyquil, qubitop_to_pyquilpauli
from zquantum.core.circuits import Circuit
from zquantum.core.interfaces.backend import QuantumSimulator
from zquantum.core.interfaces.backend import QuantumSimulator, StateVector
from zquantum.core.measurement import ExpectationValues, Measurements
from qeforest.conversions import export_to_pyquil, qubitop_to_pyquilpauli
from zquantum.core.wavefunction import flip_amplitudes


class ForestSimulator(QuantumSimulator):
Expand Down Expand Up @@ -88,11 +89,19 @@ def get_exact_expectation_values(self, circuit, qubit_operator):
)
return ExpectationValues(expectation_values)

def get_wavefunction(self, circuit):
super().get_wavefunction(circuit)
def _get_wavefunction_from_native_circuit(
self, circuit: Circuit, initial_state: StateVector
) -> StateVector:
if not np.array_equal(initial_state, [1] + [0] * (len(initial_state) - 1)):
raise ValueError(
"ForestSimulator does not support starting simulations from state "
"other than |0>. In particular, it currently does not support "
"non-native circuit components."
)

cxn = get_forest_connection(self.device_name, self.seed)
wavefunction = cxn.wavefunction(export_to_pyquil(circuit))
return wavefunction
return flip_amplitudes(wavefunction.amplitudes)


def get_forest_connection(device_name: str, seed=None):
Expand Down
19 changes: 3 additions & 16 deletions tests/qeforest/simulator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,9 @@ def test_get_wavefunction_seed(self):
for (ampl1, ampl2) in zip(wavefunction1.amplitudes, wavefunction2.amplitudes):
assert ampl1 == ampl2

def test_get_wavefunction(self, wf_simulator):
# Given
wf_simulator.number_of_circuits_run = 0
wf_simulator.number_of_jobs_run = 0
circuit = Circuit([H(0), CNOT(0, 1), CNOT(1, 2)])

# When
wavefunction = wf_simulator.get_wavefunction(circuit)

# Then
assert isinstance(wavefunction, Wavefunction)
assert len(wavefunction.probabilities()) == 8
assert wavefunction[0] == pytest.approx((1 / np.sqrt(2) + 0j), abs=1e-7)
assert wavefunction[7] == pytest.approx((1 / np.sqrt(2) + 0j), abs=1e-7)
assert wf_simulator.number_of_circuits_run == 1
assert wf_simulator.number_of_jobs_run == 1
@pytest.mark.xfail
def test_get_wavefunction_uses_provided_initial_state(self, wf_simulator):
super().test_get_wavefunction_uses_provided_initial_state(wf_simulator)


class TestForestGates(QuantumSimulatorGatesTest):
Expand Down

0 comments on commit 6584b15

Please sign in to comment.