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

Name change: backendbuddy -> linq #93

Merged
merged 4 commits into from
Dec 3, 2021
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
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
Tests/ @ValentinS4t1qbit

# Backend-agnostic code
backendbuddy/ @ValentinS4t1qbit @JamesB-1qbit
linq/ @ValentinS4t1qbit @JamesB-1qbit
1 change: 0 additions & 1 deletion docs/source/backendbuddy_basics.ipynb

This file was deleted.

1 change: 1 addition & 0 deletions docs/source/linq_basics.ipynb
2 changes: 1 addition & 1 deletion docs/source/tutorials.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Tutorials
:maxdepth: 2

overview_endtoend
backendbuddy_basics
linq_basics
vqe
dmet
problem_decomposition_oniom
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"`backendbuddy` is a submodule of `tangelo` that helps you connect to and leverage the features of various backends, may they be simulators or QPUs. This notebook talks about the abstract format used in this python package to represent a quantum circuit, and how we can then translate it to other formats or objects used in popular packages such as Qiskit, ProjectQ, Qulacs (...) and leverage the different features and performance they offer.\n",
"`linq` is a submodule of `tangelo` that helps you connect to and leverage the features of various backends, may they be simulators or QPUs. This notebook talks about the abstract format used in this python package to represent a quantum circuit, and how we can then translate it to other formats or objects used in popular packages such as Qiskit, ProjectQ, Qulacs (...) and leverage the different features and performance they offer.\n",
"\n",
"This functionality is pretty useful because it means that you can derive a given quantum circuit for any supported compute backend available with minimal effort, whether it is a simulator or an actual QPU. You therefore do not need to rewrite your program to run on a different platform, or to share your code in a specific format that your collaborators or clients expect, for publication or running an actual hardware experiment. It also means that whatever new method or code you develop can now suddenly run on all the compute backends available, enabling researchers and product users to benefit from your contributions regardless of the compute platform they intend to use.\n",
"\n",
Expand Down Expand Up @@ -47,7 +47,7 @@
"source": [
"## 1. Abstract gate class <a class=\"anchor\" id=\"1\"></a>\n",
"\n",
"The `backendbuddy` submodule is not here to provide yet another language to express a quantum circuit or to sell you an elaborate syntax to be used as a standard. Instead, it aims at providing users a straightforward and transparent way to represent a quantum gate operation, and by extension a quantum circuit.\n",
"The `linq` submodule is not here to provide yet another language to express a quantum circuit or to sell you an elaborate syntax to be used as a standard. Instead, it aims at providing users a straightforward and transparent way to represent a quantum gate operation, and by extension a quantum circuit.\n",
"\n",
"The idea is to decouple quantum circuit definition, optimization, as well as post-processing, from the actual compute backend and state preparation: users are no longer necessarily tied to a given platform for their research or experiments and can easily jump from one to another depending on their needs. Do you need a faster simulator, or to use specific noise models only supported by specific backends? No need to rewrite your whole code.\n",
"\n",
Expand Down Expand Up @@ -85,7 +85,7 @@
}
],
"source": [
"from tangelo.backendbuddy import Gate\n",
"from tangelo.linq import Gate\n",
"\n",
"# Create a Hadamard gate acting on qubit 2\n",
"H_gate = Gate(\"H\", 2)\n",
Expand Down Expand Up @@ -166,7 +166,7 @@
}
],
"source": [
"from tangelo.backendbuddy import Circuit\n",
"from tangelo.linq import Circuit\n",
"\n",
"# Here's a list of abstract gates\n",
"mygates = [Gate(\"H\", 2), Gate(\"CNOT\", 1, control=0), Gate(\"CNOT\", target=2, control=1),\n",
Expand Down Expand Up @@ -266,7 +266,7 @@
}
],
"source": [
"from tangelo.backendbuddy.helpers.circuits import measurement_basis_gates, pauli_string_to_of\n",
"from tangelo.linq.helpers.circuits import measurement_basis_gates, pauli_string_to_of\n",
"\n",
"def theta_sweep(theta, m_basis):\n",
" \"\"\" A single-parameter circuit, with change of basis at the end if needed \"\"\"\n",
Expand All @@ -276,7 +276,7 @@
" my_gates += measurement_basis_gates(pauli_string_to_of(m_basis))\n",
" return Circuit(my_gates)\n",
"\n",
"# It is easy with backendbuddy to move between string or Openfermion-style representations for Pauli words\n",
"# It is easy with linq to move between string or Openfermion-style representations for Pauli words\n",
"for theta, m_basis in [(0.1, 'ZZ'), (0.2, 'ZZ'), (0.3, 'XY')]:\n",
" c = theta_sweep(theta, m_basis)\n",
" print(f\"{c}\\n\")"
Expand Down Expand Up @@ -316,7 +316,7 @@
}
],
"source": [
"from tangelo.backendbuddy import SUPPORTED_GATES\n",
"from tangelo.linq import SUPPORTED_GATES\n",
"\n",
"for backend, gates in SUPPORTED_GATES.items():\n",
" print(f'{backend} : {gates}')"
Expand Down Expand Up @@ -427,7 +427,7 @@
}
],
"source": [
"from tangelo.backendbuddy.translator import translate_qulacs, translate_qiskit, translate_projectq, translate_qsharp, translate_openqasm, translate_cirq, translate_json_ionq, translate_braket\n",
"from tangelo.linq.translator import translate_qulacs, translate_qiskit, translate_projectq, translate_qsharp, translate_openqasm, translate_cirq, translate_json_ionq, translate_braket\n",
"\n",
"circ3_projectq = translate_projectq(circuit3)\n",
"print(f\"{circ3_projectq}\\n\")\n",
Expand Down Expand Up @@ -603,7 +603,7 @@
"\n",
"### Saving, loading and sharing quantum circuits\n",
"\n",
"The abstract circuit class used by the backendbuddy package can be translated into various formats and objects, so that users can easily save, load and share them with collaborators without providing an explicit code to do so. This is particularly relevant if you are working with external collaborators that need a circuit in a specific or general format, or if the circuit you want to share comes at the expense of complex calculations (using an application library, or maybe as a result of a variational or iterative procedure).\n",
"The abstract circuit class used by the linq package can be translated into various formats and objects, so that users can easily save, load and share them with collaborators without providing an explicit code to do so. This is particularly relevant if you are working with external collaborators that need a circuit in a specific or general format, or if the circuit you want to share comes at the expense of complex calculations (using an application library, or maybe as a result of a variational or iterative procedure).\n",
"\n",
"A first option is to use the function translating abstract format to OpenQASM, which allows you to export your circuit in a straightforward OpenQASM 2.0 text format (it relies on the QASM export from the IBM Qiskit package, as they drive the standard), which is both human readable and can be imported by other quantum circuit simulation packages in general. A \"reverse\" translation from OpenQASM back to abstract format is available as well, but only supports a subset of OPENQASM 2.0. Users can thus save as QASM and load this back into an abstract circuit as well. No need to rewrite anything.\n",
"\n",
Expand Down Expand Up @@ -640,7 +640,7 @@
}
],
"source": [
"from tangelo.backendbuddy import Simulator, backend_info\n",
"from tangelo.linq import Simulator, backend_info\n",
"\n",
"for backend, info in backend_info.items():\n",
" print(f'{backend} : {info}')"
Expand Down Expand Up @@ -762,7 +762,7 @@
"\n",
"The abstract circuit format provides a `MEASURE` instruction, supported by most compute backends, with the intent of simulating mixed states / mid-circuit measurements in the computational basis (e.g along the Z axis). As mixed states cannot be represented by a statevector, the statevector simulator backends default to simulating the quantum circuit with shots, in order to return a histogram of frequencies. Users thus must ensure the `n_shots` attribute of their `Simulator` object has been set.\n",
"\n",
"Simulating a mixed state can be considerably slower than simulating a pure state (some backends are particularly **not** good at this). Including final measurements in your state-preparation circuit is not recommended, if you intend to use `backendbuddy` to simulate it."
"Simulating a mixed state can be considerably slower than simulating a pure state (some backends are particularly **not** good at this). Including final measurements in your state-preparation circuit is not recommended, if you intend to use `linq` to simulate it."
]
},
{
Expand Down Expand Up @@ -848,7 +848,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"This notebook provided a general introduction to the `backendbuddy` submodule. I hope you liked it.\n",
"This notebook provided a general introduction to the `linq` submodule. I hope you liked it.\n",
"To dive into other topics, such as **noisy simulation** or how to use this package for **variational algorithms** for example, please refer to the other examples and tutorials available !\n",
"\n",
"---\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
}
],
"source": [
"from tangelo.backendbuddy.noisy_simulation import NoiseModel, SUPPORTED_NOISE_MODELS\n",
"from tangelo.linq.noisy_simulation import NoiseModel, SUPPORTED_NOISE_MODELS\n",
"\n",
"print(f'Supported noise models: {SUPPORTED_NOISE_MODELS}\\n')\n",
"\n",
Expand Down Expand Up @@ -106,7 +106,7 @@
}
],
"source": [
"from tangelo.backendbuddy import ONE_QUBIT_GATES, TWO_QUBIT_GATES\n",
"from tangelo.linq import ONE_QUBIT_GATES, TWO_QUBIT_GATES\n",
"\n",
"nm = NoiseModel()\n",
"\n",
Expand Down Expand Up @@ -160,7 +160,7 @@
}
],
"source": [
"from tangelo.backendbuddy import backend_info\n",
"from tangelo.linq import backend_info\n",
"from pprint import pprint \n",
"\n",
"pprint(backend_info)"
Expand Down Expand Up @@ -189,7 +189,7 @@
}
],
"source": [
"from tangelo.backendbuddy import Simulator, Gate, Circuit\n",
"from tangelo.linq import Simulator, Gate, Circuit\n",
"\n",
"# Define a noise model\n",
"nmp = NoiseModel()\n",
Expand Down Expand Up @@ -367,7 +367,7 @@
}
],
"source": [
"from tangelo.backendbuddy.noisy_simulation import get_qiskit_noise_model\n",
"from tangelo.linq.noisy_simulation import get_qiskit_noise_model\n",
"\n",
"nm = NoiseModel()\n",
"nm.add_quantum_error('RX', 'depol', 4/3)\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import numpy as np
from scipy.optimize import minimize

from tangelo.backendbuddy import Gate, Circuit, Simulator
from tangelo.linq import Gate, Circuit, Simulator


class H2StatePreparationCircuit(Circuit):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
change significantly or "grow" (such as ADAPT-VQE).
"""

from tangelo.backendbuddy import Gate, Circuit
from tangelo.linq import Gate, Circuit


class MyAnsatzCircuit(Circuit):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
Q# code needs to be written to file, as it needs to be compiled before execution, regardless of the compute backend.
"""

from tangelo.backendbuddy import Gate, Circuit
from tangelo.backendbuddy.translator import translate_qsharp
from tangelo.backendbuddy.helper_circuits import measurement_basis_gates, pauli_string_to_of
from tangelo.linq import Gate, Circuit
from tangelo.linq.translator import translate_qsharp
from tangelo.linq.helper_circuits import measurement_basis_gates, pauli_string_to_of


def theta_sweep(theta, m_basis):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Qubits are numbered left-to-right in the results, in both cases (e.g q0q1q2...)

You can elegantly generate your Q# circuits using tangelo.backendbuddy and submit them right away in one single script.
You can elegantly generate your Q# circuits using tangelo.linq and submit them right away in one single script.
"""


Expand Down Expand Up @@ -56,5 +56,5 @@

# If your Q# operation takes no parameter (results need to be retrieved through Azure portal, under the relevant Quantum Workspace).
job_id = qsharp.azure.submit(MyQsharpOperation, shots=n_shots, jobName=job_name)
# If your Q# operation takes parameters (currently not available in tangelo.backendbuddy, but you can write your own Q#):
# If your Q# operation takes parameters (currently not available in tangelo.linq, but you can write your own Q#):
# job_id = qsharp.azure.submit(MyQsharpOperation, param1=value1, param2=value2, ..., shots=n_shots, jobName=job_name')
18 changes: 9 additions & 9 deletions examples/overview_endtoend.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@
"\n",
"Quantum computers currently have limited access and capability. To study the applications of quantum computing on problem instances of reasonable size, we can use classical simulators and emulators in order to anticipate the behavior of quantum algorithms on real devices, in the presence or absence of noise. \n",
"\n",
"This package provides a submodule called `backendbuddy`, which supports a collection of open-source quantum circuit simulators delivering different performance and features. We are free to choose the most relevant backend for our use cases, thinking about resource requirements, use of shots, presence or absence of noise, and accuracy of simulation, for example. Our algorithms manipulate circuits in our own intermediary representation, and a variety of functions exist in order to convert these objects into popular formats, compatible with other open-source tools.\n",
"This package provides a submodule called `linq`, which supports a collection of open-source quantum circuit simulators delivering different performance and features. We are free to choose the most relevant backend for our use cases, thinking about resource requirements, use of shots, presence or absence of noise, and accuracy of simulation, for example. Our algorithms manipulate circuits in our own intermediary representation, and a variety of functions exist in order to convert these objects into popular formats, compatible with other open-source tools.\n",
"\n",
"The `simulate` method below runs the DMET algorithm using a simulator backend. We could specify the desired backend in the variable `dmet_options` described above when creating the `DMETProblemDecomposition` object. We however did not, and the current default choice is to go for a noiseless simulator: since our package relies on [openfermion](https://quantumai.google/openfermion), which installs [cirq](https://quantumai.google/cirq) as a dependency, `cirq` will be the default backend unless [qulacs](https://github.com/qulacs/qulacs) is found in your environment. Currently other supported local backends include [qiskit](https://qiskit.org/) and [QDK](https://azure.microsoft.com/en-us/resources/development-kit/quantum-computing/).\n"
]
Expand Down Expand Up @@ -602,8 +602,8 @@
}
],
"source": [
"from tangelo.backendbuddy import Circuit, Gate\n",
"from tangelo.backendbuddy.helpers.circuits.measurement_basis import measurement_basis_gates\n",
"from tangelo.linq import Circuit, Gate\n",
"from tangelo.linq.helpers.circuits.measurement_basis import measurement_basis_gates\n",
"\n",
"# Creation of XX, XZ, ZX, ZZ and YY circuits.\n",
"# This is done by appending relevant gates to the quantum circuit representing the quantum state.\n",
Expand Down Expand Up @@ -730,7 +730,7 @@
"os.environ['QEMIST_AUTH_TOKEN'] = \"your_qemist_authentication_token\"\n",
"\n",
"# Estimate, submit and get the results of your job / quantum task through our wrappers\n",
"from tangelo.backendbuddy.qpu_connection import job_submit, job_status, job_cancel, job_result, job_estimate\n",
"from tangelo.linq.qpu_connection import job_submit, job_status, job_cancel, job_result, job_estimate\n",
"\n",
"circuit_YY = quantum_circuit[((0, \"Y\"), (1, \"Y\"))]\n",
"\n",
Expand All @@ -751,7 +751,7 @@
"source": [
"### Using a cloud API and format conversion <a class=\"anchor\" id=\"82\"></a>\n",
"\n",
"The utility functions in `tangelo.backendbuddy` allow us to convert our generic `Circuit` objects into a variety of formats supported by other open-source packages and services, such as Amazon's Braket and Microsoft's Azure Quantum.\n",
"The utility functions in `tangelo.linq` allow us to convert our generic `Circuit` objects into a variety of formats supported by other open-source packages and services, such as Amazon's Braket and Microsoft's Azure Quantum.\n",
"\n",
"You can thus convert a `Circuit` object into the desired format and use the API of those services directly in order to reach a QPU or an online simulator if you wish to do so. The example below shows how to convert a `Circuit` object into the Braket format. Provided that you have a Braket account, the submission process is pretty straightforward, as demonstrated by the [documentation](https://github.com/aws/amazon-braket-sdk-python#usage)"
]
Expand All @@ -778,7 +778,7 @@
}
],
"source": [
"from tangelo.backendbuddy.translator import translate_braket\n",
"from tangelo.linq.translator import translate_braket\n",
"\n",
"braket_circuit = translate_braket(circuit_YY)\n",
"print(braket_circuit)"
Expand Down Expand Up @@ -809,7 +809,7 @@
}
],
"source": [
"from tangelo.backendbuddy.translator import translate_cirq\n",
"from tangelo.linq.translator import translate_cirq\n",
"\n",
"cirq_circuit = translate_cirq(circuit_YY)\n",
"print(cirq_circuit)"
Expand All @@ -836,8 +836,8 @@
},
"outputs": [],
"source": [
"from tangelo.backendbuddy import Simulator\n",
"from tangelo.backendbuddy.noisy_simulation import NoiseModel\n",
"from tangelo.linq import Simulator\n",
"from tangelo.linq.noisy_simulation import NoiseModel\n",
"\n",
"nmp = NoiseModel()\n",
"nmp.add_quantum_error(\"CNOT\", \"depol\", 0.01)\n",
Expand Down
4 changes: 2 additions & 2 deletions examples/qemist_cloud_hardware_experiments_braket.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
}
],
"source": [
"from tangelo.backendbuddy import Gate, Circuit\n",
"from tangelo.linq import Gate, Circuit\n",
"\n",
"circuit = Circuit([Gate(\"H\", 0), Gate(\"CNOT\", 1, control=0)])\n",
"print(circuit)"
Expand All @@ -110,7 +110,7 @@
"metadata": {},
"outputs": [],
"source": [
"from tangelo.backendbuddy.qpu_connection import job_submit, job_status, job_cancel, job_result, job_estimate"
"from tangelo.linq.qpu_connection import job_submit, job_status, job_cancel, job_result, job_estimate"
]
},
{
Expand Down
8 changes: 4 additions & 4 deletions examples/test_notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ def run_notebook_as_test(notebook_path):
class TestNotebooks(unittest.TestCase):
""" Turn target Python notebooks into script, run them as unittests (pass = no errors at runtime) """

def test_backendbuddy_basics_notebook(self):
run_notebook_as_test('backendbuddy/1.the_basics.ipynb')
def test_linq_basics_notebook(self):
run_notebook_as_test('linq/1.the_basics.ipynb')

def test_backendbuddy_noisy_simulation_notebook(self):
run_notebook_as_test('backendbuddy/3.noisy_simulation.ipynb')
def test_linq_noisy_simulation_notebook(self):
run_notebook_as_test('linq/3.noisy_simulation.ipynb')

def test_dmet_notebook(self):
run_notebook_as_test('./dmet.ipynb')
Expand Down
Loading