Skip to content

Commit

Permalink
Merge pull request #21 from calculquebec/release
Browse files Browse the repository at this point in the history
Release v0.4.0
  • Loading branch information
Scirelgar authored Oct 1, 2024
2 parents d04c7ef + bbf8c66 commit 707d70f
Show file tree
Hide file tree
Showing 12 changed files with 206 additions and 115 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pip install -e .

Pennylane and other Python dependencies will be installed automatically during the installation process.

The plugin will also take care of installing Julia and the required Julia packages, such as Snowflurry, PythonCall during the first run. Some notes on that matter are provided below.
The plugin will also take care of installing Julia and the required Julia packages, such as Snowflurry and PythonCall during the first run. Some notes on that matter are provided below.

If you wish to disable this behaviour, you can edit the julia_env.py file and set the value of the variable `IS_USER_CONFIGURED` to `TRUE`:

Expand Down Expand Up @@ -81,7 +81,7 @@ dev_def = qml.device("snowflurry.qubit", wires=1, shots=50)
Example if you have an API key from Anyon Systems:

```py
dev_def = qml.device("snowflurry.qubit", wires=1, shots=50, host="example.anyonsys.com", user="test_user",access_token="not_a_real_access_token")
dev_def = qml.device("snowflurry.qubit", wires=1, shots=50, host="example.anyonsys.com", user="test_user",access_token="not_a_real_access_token", realm="realm_name")
```

## State of the project and known issues
Expand All @@ -91,3 +91,5 @@ This plugin is still very early in its development and aims to provide a basic i
### Future plans

- Add a test suite to ensure the plugin works as expected.
- Integrate a compiler to optimize the circuits.
- Add device that allows for communication with MonarQ directly through its API.
2 changes: 1 addition & 1 deletion pennylane_snowflurry/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
"""


__version__ = "0.3.0"
__version__ = "0.4.0"
2 changes: 1 addition & 1 deletion pennylane_snowflurry/julia_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Required packages for the Julia environment
REQUIRED_PACKAGES = [
PkgSpec(
name="Snowflurry", uuid="7bd9edc1-4fdc-40a1-a0f6-da58fb4f45ec", version="0.3"
name="Snowflurry", uuid="7bd9edc1-4fdc-40a1-a0f6-da58fb4f45ec", version="0.4"
),
]

Expand Down
6 changes: 6 additions & 0 deletions pennylane_snowflurry/measurements/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from .measurement_strategy import MeasurementStrategy
from .counts import Counts
from .sample import Sample
from .probabilities import Probabilities
from .state import State
from .expectation_value import ExpectationValue
26 changes: 26 additions & 0 deletions pennylane_snowflurry/measurements/counts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from .measurement_strategy import MeasurementStrategy
from collections import Counter


class Counts(MeasurementStrategy):

def __init__(self):
super().__init__()

def measure(self, converter, mp, shots):
if self.Snowflurry.currentClient is None:
converter.remove_readouts()
converter.apply_readouts(mp.obs)
shots_results = self.Snowflurry.simulate_shots(self.Snowflurry.sf_circuit, shots)
result = dict(Counter(shots_results))
return result
else: # if we have a client, we use the real machine
converter.apply_readouts(mp.obs)
qpu = self.Snowflurry.AnyonYamaskaQPU(
self.Snowflurry.currentClient, self.Snowflurry.seval("project_id")
)
shots_results, time = self.Snowflurry.transpile_and_run_job(
qpu, self.Snowflurry.sf_circuit, shots
)
result = dict(Counter(shots_results))
return result
26 changes: 26 additions & 0 deletions pennylane_snowflurry/measurements/expectation_value.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from .measurement_strategy import MeasurementStrategy
import pennylane as qml
from juliacall import convert
import numpy as np


class ExpectationValue(MeasurementStrategy):

def __init__(self):
super().__init__()

def measure(self, converter, mp, shots):
# FIXME : this measurement does work when the number of qubits measured is not equal to the number of qubits
# in the circuit
# Requires some processing to work with larger matrices
converter.remove_readouts()
self.Snowflurry.result_state = self.Snowflurry.simulate(self.Snowflurry.sf_circuit)
if mp.obs is not None and mp.obs.has_matrix:
print(mp.obs)
observable_matrix = qml.matrix(mp.obs)
print(observable_matrix)
expected_value = self.Snowflurry.expected_value(
self.Snowflurry.DenseOperator(convert(self.Snowflurry.Matrix, observable_matrix)),
self.Snowflurry.result_state
)
return np.real(expected_value)
11 changes: 11 additions & 0 deletions pennylane_snowflurry/measurements/measurement_strategy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from abc import ABC, abstractmethod


class MeasurementStrategy:

def __init__(self):
from pennylane_snowflurry.pennylane_converter import Snowflurry
self.Snowflurry = Snowflurry

def measure(self, converter, mp, shots):
pass
19 changes: 19 additions & 0 deletions pennylane_snowflurry/measurements/probabilities.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from .measurement_strategy import MeasurementStrategy
from juliacall import convert


class Probabilities(MeasurementStrategy):

def __init__(self):
super().__init__()

def measure(self, converter, mp, shots):
converter.remove_readouts()
wires_list = mp.wires.tolist()
if len(wires_list) == 0:
return self.Snowflurry.get_measurement_probabilities(self.Snowflurry.sf_circuit)
else:
return self.Snowflurry.get_measurement_probabilities(
self.Snowflurry.sf_circuit,
convert(self.Snowflurry.Vector, [i + 1 for i in wires_list])
)
27 changes: 27 additions & 0 deletions pennylane_snowflurry/measurements/sample.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from .measurement_strategy import MeasurementStrategy
import numpy as np


class Sample(MeasurementStrategy):

def __init__(self):
super().__init__()

def measure(self, converter, mp, shots):
if self.Snowflurry.currentClient is None:
converter.remove_readouts()
converter.apply_readouts(mp.obs)
shots_results = self.Snowflurry.simulate_shots(self.Snowflurry.sf_circuit, shots)
return np.asarray(shots_results).astype(int)
else:
converter.apply_readouts(mp.obs)
qpu = self.Snowflurry.AnyonYamaskaQPU(
self.Snowflurry.currentClient, self.Snowflurry.seval("project_id")
)
shots_results, time = self.Snowflurry.transpile_and_run_job(
qpu, self.Snowflurry.sf_circuit, shots,
)
return np.repeat(
[int(key) for key in shots_results.keys()],
[value for value in shots_results.values()],
)
16 changes: 16 additions & 0 deletions pennylane_snowflurry/measurements/state.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from .measurement_strategy import MeasurementStrategy

import numpy as np


class State(MeasurementStrategy):

def __init__(self):
super().__init__()

def measure(self, converter, mp, shots):
converter.remove_readouts()
self.Snowflurry.result_state = self.Snowflurry.simulate(self.Snowflurry.sf_circuit)
# Convert the final state from pyjulia to a NumPy array
final_state_np = np.array([element for element in self.Snowflurry.result_state])
return final_state_np
Loading

0 comments on commit 707d70f

Please sign in to comment.