Git Product home page Git Product logo

floq-client's Introduction

Floq API client

This client uses the cirq interface to submit quantum circuits to the Floq Service. This client is designed to be simple to use for those familiar with the cirq.Simulator interface.

Installation

python3 -m virtualenv venv --python=python3.8  # At least Python 3.7
source venv/bin/activate
pip install floq_client

Documentation

Full documentation is available at https://floq-client.readthedocs.io/

Usage

Currently the Floq client supports cirq's SimulatesSamples and the SimulatesExpectationValues simulators. These interfaces include methods for running sampling and calculating expectation values of single circuits, batches of circuits or circuits to be resolved with parameter value sweeps.

Check out the samples in the samples directory.

SimulatesSamples

import floq.client

qubits = cirq.LineQubit.range(26)
param_resolver = cirq.ParamResolver({'a': 1})
a = sympy.Symbol('a')
circuit = cirq.Circuit(
    [cirq.X(q) ** a for q in qubits] +
    [cirq.measure(q) for q in qubits])

client = floq.client.CirqClient("my_api_key")
result = client.simulator.run(circuit, param_resolver) # Results from the cloud hurray!

See SimulatesSamples interface documentation for more information.

Note: This client does not support the async run calls currently.

SimulatesExpectationValues

See SimulatesExpectationValues interface documentation for more information.

The client also provides calculation of expectation values against cirq.PauliSum observables:

import floq.client

client = floq.client.CirqClient("my_api_key")

# Find expectation against a single Paulisum
magnetization_op = sum([cirq.Z(q) for q in qubits])
client.simulator.simulate_expectation_values(
    circuit,
    magnetization_op,
    param_resolvers)

    # returns [exp_value]

# Or against multiple
client.simulator.simulate_expectation_values(
    circuit,
    [magnetization_op, cirq.X(qubits[0]) + cirq.Y(qubits[0])]
)
    # returns [exp1, exp2] - one expectation per observable

# Also run sweeps over param_resolver values
client.simulator.simulate_expectation_values_sweep(
    circuit,
    [observable1, observable2],
    cirq.Sweepable
)
    # returns [[exp1, exp2], ...] - one list of expectations per param set

Note: The SimulatesExpectationValues interface is available in cirq>=0.10.0.

Jobs Queue manager

Floq client also provides an interface for inspecting and flushing pending jobs queue. Each time a quantum circuit is submitted to the cloud, the Floq service replies with unique job id and the job is queued for the execution.

The example code is located in jobs_queue.py sample file.

TPU worker manager

Each individual API key is bound to dedicated TPU worker running in the cloud. The Floq Client provides an interace for starting, stopping or restarting the worker (in case it enters into some unexpected state). Additionally, you can always check current worker status.

The example code is located in worker_manager.py sample file.

CLI script

Both jobs queue and TPU worker can be controlled manually using provided CLI script. Simply provide Floq API key as the input argument and the resource command as shown below:

# Jobs queue commands
floq-client API_KEY jobs {display,flush}

# TPU worker commands
floq-client API_KEY worker {restart,start,stop,status}

PennyLane-Cirq with Floq

To use Floq-backend in PennyLane, please install the latest version of PennyLane-Cirq plugin. The sample code is located in the pennylane.py file.

Caveats

Keep in mind that you are on the frontier and this is a very experimental service! There will be trials, tribulations, and bugs!

Please let us know about issues you encounter and mail us at [email protected].

That being said there are a few known limitations at this point. In order to be conservative we have implemented restrictions on the size of circuits, number of observables, etc... We are working hard to push this forward, bear with us.

Enjoy!

floq-client's People

Contributors

floqclientbot avatar jaeyoo avatar twojno avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

floq-client's Issues

Intermittent (random?) `ServiceError`s

Expected Behavior

Ability to simulate a Cirq circuit with floq.client.CirqClient.

Actual Behavior

Raises ServiceError: API service error: The current request is not defined by this API. roughly half (?) the time when running the following codeblock. Seems to fail more frequently with larger circuits, and seems to be independent of the gate.

Steps to Reproduce the Problem

import cirq
import floq.client

client = floq.client.CirqClient(api_key=API_KEY)

q = cirq.GridQubit(0, 0)
circuit = cirq.Circuit(cirq.H.on(q), cirq.measure(q))
client.simulator.run(circuit)
# >>> ServiceError: API service error: The current request is not defined by this API.

Specifications

  • Version: 0.1.1
  • Platform: Python 3.7.11 on Colab

AttributeError: 'CirqSimulator' object has no attribute 'simulate'.

Expected Behavior

PennyLane-Cirq with Floq should work without any error.

Actual Behavior

When the Floq client simulator is set into PennyLane, it says the following error:

AttributeError: 'CirqSimulator' object has no attribute 'simulate'.

Specifications

  • Version: the latest pennylane-cirq
  • Platform: Colab notebook

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.