Giter VIP home page Giter VIP logo

pytket-docs's Introduction

pytket-docs

Slack PyPI version Binder

Pytket is a python module for interfacing with tket, a quantum computing toolkit and optimising compiler developed by Quantinuum.

This repository contains the user manual and example notebooks to get you started using pytket. It does not contain source code. The source code is maintained on the tket repository.

The notebook examples are built with jupyterbook and can be viewed at https://tket.quantinuum.com/examples.

Instructions for how to add jupyter notebooks to the examples repository can be found here.

For more on how the user manual is built and deployed see the manual README.

Getting started

Pytket is available for Python 3.10, 3.11 and 3.12 on Linux, MacOS and Windows. To install, run:

pip install pytket

See the Getting Started page for a quick introduction to using pytket.

API documentation can be found at https://tket.quantinuum.com/api-docs.

To get more in depth on features, see the manual and examples.

Extensions

It is easy to use pytket as a front-end for interacting with third-party devices and software.

We maintain a large and growing number of pytket extensions. These extensions provide access to a range of quantum devices and simulators and enable joint functionality between pytket and other quantum software libraries.

These are simple to install with pip.

Maintenance and support

If you think you've found a bug or have an idea for a feature then please raise an issue here.

There is also a slack channel for discussion and support. click here to join.

Pytket 0.x.y

Pytket underwent rapid development from 2018 to 2022, with frequent changes of API. Our policy has been to maintain only the latest 0.x relase, and not to port bugfixes to older releases. Since version 0.7 (February 2021) we have been releasing new versions (0.x.0) on a 4-week cycle, with occasional patch releases (0.x.y) for important hotfixes.

Pytket 1.x.y

With the release of pytket 1.0 in early 2022, we are moving to a different process, to facilitate long-term stability. Following the semver conventions, we will not introduce incompatible API changes in the 1.x.y series; the minor version (x) will be incremented whenever new functionality is introduced; and the patch version (y) will be incremented for bug fixes.

Pytket 1 will be maintained according to this policy for at least a year following the release of pytket 2.0. There will be no further maintenance of 0.x.y versions.

Pytket 2.x.y

Development work on pytket 2 will begin soon after the release of pytket 1.0. This will have a different API. Only pre-release versions will be uploaded to pypi until the API has stabilized enough to make a 2.0 release. Thereafter we will continue according to the same policy as for pytket 1.x.y.

How to cite

If you wish to cite tket in any academic publications, we generally recommend citing our software overview paper for most cases.

If your work is on the topic of specific compilation tasks, it may be more appropriate to cite one of our other papers:

We are also keen for others to benchmark their compilation techniques against us. We recommend checking our benchmark repository for examples on how to run basic benchmarks with the latest version of pytket. Please list the release version of pytket with any benchmarks you give, and feel free to get in touch for any assistance needed in setting up fair and representative tests.

pytket-docs's People

Contributors

alexcowtan avatar calmaccq avatar cqc-alec avatar cqc-melf avatar dependabot[bot] avatar ferbetanzo avatar isobelhooper avatar lmondada avatar roland-djee avatar sjdilkes avatar ss2165 avatar willsimmons1465 avatar yao-cqc avatar

Stargazers

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

Watchers

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

pytket-docs's Issues

Best pass(es) for optimization?

Hi, I'm working on an updated version of our paper on verified optimization of quantum circuits. I'd like to update tket's results on our benchmarks. What is the best pass (or passes) to use for evaluating optimization (without routing)? For an even comparison, I'd like the output gate set to be {u1, u2, u3, CX}.

For reference, my current script for running tket is here. It uses FullPeepholeOptimise.

Thanks!

Edit: I'm also interested in how to get tket to output circuits in the gate set {Rz, X, H, CX}. If I do a Rebase after optimization, will I end up losing benefits from optimization?

Place with map gives an error

When trying to follow routing_example.ipynb from pytket tutorials and invoking place_with_map(...) function I encounter a strange error:
TypeError: place_with_map(): incompatible function arguments. The following argument types are supported:
1. (circuit: pytket.circuit.Circuit, qmap: pytket.routing.QubitMap) -> None

It looks like I pass correct arguments, however I still get the error.
The error occurs both in pytket 0.6.0 and pytket 0.5.4.

image

`symbolics_example` notebook fails with pytket-qiskit 0.17.0

(env) alec@psi:~/r/pytket/examples/python$ python symbolics_example.py
a
a_1
┌───┐┌─────────┐┌───┐ »
q_0: ──■───────────────────────────────────■───────┤ X ├┤ Rz(πb) ├┤ X ├───────■─────────────────────────────────»
┌─┴─┐ ┌─┴─┐┌───┐└─┬─┘└─────────┘└─┬─┘┌───┐┌─┴─┐ »
q_1: ┤ X ├──■─────────────────────────■──┤ X ├┤ X ├──■───────────────■──┤ X ├┤ X ├──■─────────────────────────■──»
└───┘┌─┴─┐ ┌─┴─┐├───┤└─┬─┘ └─┬─┘├───┤┌─┴─┐ ┌─┴─┐»
q_2: ─────┤ X ├──■───────────────■──┤ X ├┤ X ├──■─────────────────────────■──┤ X ├┤ X ├──■───────────────■──┤ X ├»
└───┘┌─┴─┐┌─────────┐┌─┴─┐└───┘└─┬─┘ └─┬─┘└───┘┌─┴─┐┌─────────┐┌─┴─┐└───┘»
q_3: ──────────┤ X ├┤ Rz(π
a) ├┤ X ├───────■───────────────────────────────────■───────┤ X ├┤ Rz(π/2) ├┤ X ├─────»
└───┘└─────────┘└───┘ └───┘└─────────┘└───┘ »
«
«q_0: ──■──
« ┌─┴─┐
«q_1: ┤ X ├
« └───┘
«q_2: ─────
«
«q_3: ─────
«
Traceback (most recent call last):
File "symbolics_example.py", line 66, in
print_tkcirc_via_qiskit(circ)
File "symbolics_example.py", line 57, in print_tkcirc_via_qiskit
qiskit_qcirc = tk_to_qiskit(tkcirc)
File "/home/alec/r/pytket/env/lib/python3.8/site-packages/pytket/extensions/qiskit/qiskit_convert.py", line 537, in tk_to_qiskit
append_tk_command_to_qiskit(
File "/home/alec/r/pytket/env/lib/python3.8/site-packages/pytket/extensions/qiskit/qiskit_convert.py", line 494, in append_tk_command_to_qiskit
qcirc.global_phase += phase * sympy.pi
File "/home/alec/r/pytket/env/lib/python3.8/site-packages/qiskit/circuit/parameterexpression.py", line 306, in add
return self._apply_operation(operator.add, other)
File "/home/alec/r/pytket/env/lib/python3.8/site-packages/qiskit/circuit/parameterexpression.py", line 255, in _apply_operation
elif isinstance(other, numbers.Number) and numpy.isfinite(other):
TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

pytket 0.7.0 pins to openfermion 0.11

We'd like to use pytket 0.7 with openfermion 1.0+. Is there actually some restriction preventing this from working? Why is pytket using openfermion anyways :)

Error when trying to use ibmq_armonk

Hi!

Trying to use the ibmq_armonk device as a backend raises an error:


TypeError Traceback (most recent call last)
in ()
----> 1 ibmq_b = IBMQBackend('ibmq_armonk')

1 frames
/usr/local/lib/python3.6/dist-packages/pytket/qiskit/qiskit_convert.py in process_device(backend)
195 node_ers_dict = {}
196 link_ers_dict = {tuple(pair): GateErrorContainer()
--> 197 for pair in coupling_map}
198
199 for index, qubit_info in enumerate(properties.qubits):

TypeError: 'NoneType' object is not iterable

It seems that a coupling_map is expected for any device, but ibmq_armonk has a single qubit and, hence, no coupling_map.

Wrong result with pytket-qulacs

from numpy import pi
import pytket as tket
from pytket.qulacs import tk_to_qulacs
from qulacs import QuantumState

qc = tket.Circuit(1)
qc.Rx(0.5, 0)

qc = tk_to_qulacs(qc)

state = QuantumState(1)
qc.update_quantum_state(state)

print(state.get_vector())
----
Output:
[0.70710678+0.j         0.+0.70710678j]
Expected Output:
[0.70710678+0.j         0.-0.70710678j]

From Qulacs documentation:
Rotation gates RX, RY, and RZ operate as Pauli rotation exp(𝑖𝜃/2𝑃) based on corresponding Pauli operator 𝑃 and argument 𝜃

Since tket uses exp(-𝑖aπ/2𝑃) representation, arguments of rotation gates should be multiplied by -1 inside tk_to_qulacs.

pytket-cirq is too specific when pinning to cirq

xref: quantumlib/ReCirq#61

When trying to install the latest release of cirq, which is 0.8.2, you get:

error: cirq 0.8.2 is installed but cirq==0.8 is required by {'pytket-cirq'}

I suspect this is because the pin is too specific. If you change it to cirq~=0.8 it will work with point releases. Ironically, this point release was to fix some dependency management bugs!

qubit map in pytket.routing.route()?

Hi,

in an earlier version of pytket it was possible to use the function route() get back the qubit map from the initial placement of the qubits (before the routing) and the final placement after the routing.

tk_routed, qmap = route(tk_circ, arc)

In the new version the function 'pytket.routing.route()' just gives back the routed circuit. Is there still functionality to get back the qubit mapping?

Thanks!
Michael

PS: the link to your cirq-routing example seems to be broken (https://github.com/CQCL/pytket/blob/master/examples/cirq_routing_example.ipynb).

When specifying a full custom initial mapping, convert_index_mapping() fails to map correctly

While following along the "routing_example" tutorial, I noticed that if you try to give a custom initial mapping using convert_index_mapping() using IBM's Melbourne hardware graph, it doesn't not respect the initial mapping.

Steps to reproduce the problem

# Grab melbourne backend from qiskit
from qiskit import IBMQ
IBMQ.load_account()
provider = IBMQ.providers()[0]
mel_backend = provider.get_backend('ibmq_16_melbourne')

# Get melbourne device properties
from pytket.backends.ibm.ibm import process_device
mel_dev = process_device(mel_backend)

from pytket.routing import convert_index_mapping
from pytket.qasm import circuit_from_qasm

# Load circuit
loc = 'path/to/IBM/circuit/4gt12-v0_87.qasm'
ex_circ = circuit_from_qasm(loc)

# Define allocation to use for circuit with melbourne
full_allocation = {0: 12, 1: 2, 2: 3, 3: 4, 4: 10, 5: 11}

# Define the function used to look at the mapping from the tutorial example
def print_qubit_mapping(the_map):
    print('Qubit to Node mapping:')
    for k, v in the_map.items():
        print(k, v)

# Get the QubitMapping object
custom_map = convert_index_mapping(ex_circ, mel_dev, full_allocation)
print_qubit_mapping(custom_map)

output

Qubit to Node mapping:
q[0] node[9]
q[1] node[14]
q[2] node[2]
q[3] node[13]
q[4] node[10]
q[5] node[6]

Unless I'm misunderstanding something, I'd expect that the 'node' indices here should be the values specified in the 'full_allocation' dictionary that we gave to 'convert_index_mapping()'. Hence, it seems that that the function is failing to create the actual QubitMap that you expect.

I tried changing the qreg size, removing the classical register, switching circuits, using a different hardware graph (I tried 'ourense' which also failed) as well as using an Architecture(edge_list) pass instead of using the device object pass to no avail. Using Architecture(melbourne_edge_list) improved on the matching accuracy with reference to the allocation dictionary, but still failed to get all of the qubits mapped correctly (got 5/6 right).

My apologies if I'm just using the library wrong, I'm new to pytket.

No mapping for custom Qiskit 'qiskit.circuit.Gate' objects

There doesn't seem to be any mapping in qiskit_convert.py for custom gates constructed in Qiskit via the QuantumCircuit.to_gate method. I resolved this locally for now by adding a mapping from Qiskit qiskit.circuit.Gate to pytket's custom gate via pytket.circuit.CustomGateDef, which seems to work.

Github Release and PyPI Version are Out of Sync

Would it be possible to update the Github release version (currently 0.3.0) so that it corresponds to what is in PyPI (0.4.1)? This helps when requesting open-source libraries be pulled into restricted software development environments.

Memory corruption with symbolic circuits on Windows

Version: pytket 0.6.0

Certain operations with symbolic circuits on Windows cause the program to exit, sometimes with a message about an access violation.

For a simple example:

from pytket.circuit import Circuit
from sympy import Symbol, cos

a = Symbol("a")
t = a + cos(a)
c = Circuit(1)
i = 0
while True:
    print(i)
    c.Ry(t, 0)
    i += 1

This will run for a variable number of iterations (typically between 1 and 20) before terminating.

The telemetry module shouldn't write to config file on load

When loading the telemetry module, t|ket> always write to the config file (telemetry/__init__.py):

def _on_module_load() -> None:
    [...]
    # assumes read_file can deal with old version of config on disc
    # and write out a valid new version
    config.write_file(pytket_config_file)
    [...]

This behaviour seems unecessary: If config.read_file can deal with old versions of config, then there should be no reason for it to rewrite the file. This behaviour is also troubling: When running different instances of t|ket> in parallel, this reading and writing obviously causes race conditions that break things from time to time.

Memory leak when symbolic circuits used with scipy.minimize

Using the following energy objective function, modeled after the Oxford QIS workshop https://github.com/CQCL/pytket/blob/master/examples/oxfordQIS.py :

    def objective_function(params: list):
        ansatz_at_params = ansatz.copy()
        symbol_map = dict(zip(symbols, params))
        ansatz_at_params.symbol_substitution(symbol_map)
        energy = backend.get_operator_expectation_value(ansatz_at_params,
                                                        QubitPauliOperator.from_OpenFermion(hamiltonian))

        return energy.real`

where ansatz is the symbolic Circuit of a molecular ansatz and symbols is a dictionary of the symbolised parameters, when fed into scipy.minimize for optimising the parameters, memory is not being deallocated properly and it slowly eats up RAM (see below):

image

`qiskit_integration` notebook fails with pytket-qiskit 0.17.0

(env) alec@psi:~/r/pytket/examples/python$ python qiskit_integration.py 
Exact result: -1.857275030202379
Traceback (most recent call last):
  File "qiskit_integration.py", line 71, in <module>
    print("VQE result:", vqe_solve(H2_op, 50, qi))
  File "qiskit_integration.py", line 48, in vqe_solve
    return vqe.compute_minimum_eigenvalue(op).eigenvalue
  File "/home/alec/r/pytket/env/lib/python3.8/site-packages/qiskit/algorithms/minimum_eigen_solvers/vqe.py", line 490, in compute_minimum_eigenvalue
    opt_params, opt_value, nfev = self.optimizer.optimize(
  File "/home/alec/r/pytket/env/lib/python3.8/site-packages/qiskit/algorithms/optimizers/spsa.py", line 556, in optimize
    return self._minimize(objective_function, initial_point)
  File "/home/alec/r/pytket/env/lib/python3.8/site-packages/qiskit/algorithms/optimizers/spsa.py", line 430, in _minimize
    get_eta, get_eps = self.calibrate(loss, initial_point)
  File "/home/alec/r/pytket/env/lib/python3.8/site-packages/qiskit/algorithms/optimizers/spsa.py", line 281, in calibrate
    delta = loss(initial_point + c * pert) - loss(initial_point - c * pert)
  File "/home/alec/r/pytket/env/lib/python3.8/site-packages/qiskit/algorithms/minimum_eigen_solvers/vqe.py", line 563, in energy_evaluation
    means = np.real(sampled_expect_op.eval())
  File "/home/alec/r/pytket/env/lib/python3.8/site-packages/qiskit/opflow/list_ops/list_op.py", line 424, in eval
    evals = [op.eval(front) for op in self.oplist]
  File "/home/alec/r/pytket/env/lib/python3.8/site-packages/qiskit/opflow/list_ops/list_op.py", line 424, in <listcomp>
    evals = [op.eval(front) for op in self.oplist]
  File "/home/alec/r/pytket/env/lib/python3.8/site-packages/qiskit/opflow/list_ops/list_op.py", line 424, in eval
    evals = [op.eval(front) for op in self.oplist]
  File "/home/alec/r/pytket/env/lib/python3.8/site-packages/qiskit/opflow/list_ops/list_op.py", line 424, in <listcomp>
    evals = [op.eval(front) for op in self.oplist]
  File "/home/alec/r/pytket/env/lib/python3.8/site-packages/qiskit/opflow/list_ops/composed_op.py", line 141, in eval
    return reduce(tree_recursive_eval, reversed(eval_list))
  File "/home/alec/r/pytket/env/lib/python3.8/site-packages/qiskit/opflow/list_ops/composed_op.py", line 131, in tree_recursive_eval
    return l_arg.eval(r)
  File "/home/alec/r/pytket/env/lib/python3.8/site-packages/qiskit/opflow/state_fns/operator_state_fn.py", line 251, in eval
    return front.adjoint().eval(cast(OperatorBase, self.primitive.eval(front))) * self.coeff
  File "/home/alec/r/pytket/env/lib/python3.8/site-packages/qiskit/opflow/primitive_ops/pauli_sum_op.py", line 309, in eval
    raise ValueError(
ValueError: eval does not support operands with differing numbers of qubits, 2 and 1, respectively.

No mapping for Qiskit multi-controlled gates during circuit conversion to Pytket

In pytket version 0.6.0, there seems to be no mapping for Qiskit's multi-controlled gates. For example, the multi-controlled X: QuantumCircuit.mct and QuantumCircuit.mcx.

Internally, in Qiskit's QuantumCircuit, these map to one of the different implementations like MCXVChain and MCXGrayCode only when the number of control qubits is greater than two.

Locally, for the X gate, I resolved this by mapping all of these variants to pytket's OpType.CnX for now.

Missing requirements in documentation

When I tried to run cirq_routing_example.ipynb, I expected pytket to run the example correctly; instead I get an import error.

Upon inspection, I noticed this message:

Library not loaded: /usr/local/opt/boost/lib/libboost_graph-mt.dylib

I assumed that the solution then was that I did not have the Boost C++ libraries installed. I installed them using Homebrew and now the examples run fine.

However, in the documentation Boost is not mentioned as a requirement, so I think that the installation instructions should be updated.

The same happens if you try to run pyquil_example.ipynb and tket_benchmarking.ipynb, since they require pandas and quantum-groove to be installed.

After installing them via pip I was able to run all the code successfully.

Environment

  • Mac OS Mojave 10.14.3 (clean install)
  • Python 3.7

Potential solution

Add Boost C++ Libraries as an explicit requirement (for Mac OS only?).

pandas and quantum-groove should be added in requirements.txt, or the documentation should mention that you need to install them to run the examples.

Error from routing example notebook

Running the routing_example notebook generates an error when trying to route a circuit.

The following reduced snippet illustrates the problem:

from pytket.circuit import Circuit, Qubit, Node
from pytket.device import Device
from pytket.routing import route, place_with_map
from qiskit import IBMQ

IBMQ.load_account()

from pytket.extensions.qiskit import process_characterisation

provider = IBMQ.providers()[0]
athens_backend = provider.get_backend("ibmq_athens")
athens_characterisation = process_characterisation(athens_backend)
athens_device = Device(
    athens_characterisation["NodeErrors"],
    athens_characterisation["EdgeErrors"],
    athens_characterisation["Architecture"],
)

example_circuit = Circuit(4)
example_circuit.CX(0, 1).CX(0, 2).CX(1, 2).CX(3, 2).CX(0, 3)

partial_initial_index_map = {0: 1}
partial_initial_map = {Qubit(i): Node(j) for i, j in partial_initial_index_map.items()}

partial_ex_circ = example_circuit.copy()
place_with_map(partial_ex_circ, partial_initial_map)
partial_routed_circuit = route(partial_ex_circ, athens_device)

Output:

RuntimeError: At least one component must be selected to be able to propagate

This is with pytket 0.10.0, pytket-qiskit 0.10.0.

Issue with CircBox and converting Qiskit circuits that use 'to_instruction()'

Analysis and Reproducing the Issue
Consider the following code that runs a simple Qiskit circuit and converting it to a Pytket circuit. The circuit runs on IBM's AerBackend:

    from pytket.qiskit import qiskit_to_tk
    from pytket.backends.ibm import AerBackend
    from qiskit import QuantumCircuit, QuantumRegister

    boxed_circuit = QuantumCircuit(2)
    boxed_circuit.cx(0, 1)

    main_circuit = QuantumCircuit(2, 2)
    main_circuit.h(range(2))
    main_circuit.append(boxed_circuit.to_instruction(), range(2))
    main_circuit.measure(range(2),range(2))

    backend = AerBackend()
    tk = qiskit_to_tk(main_circuit)

    backend.compile_circuit(tk)
    res = backend.process_circuits([tk], n_shots=124)
    print(res[0].get_counts())

However, when the circuit is being validated against the GateSetPredicate an error occurs:
pytket.backends.backend_exceptions.CircuitNotValidError: Circuit with index 0 in submitted does not satisfy GateSetPredicate:{ Unitary1qBox Measure noop T CU1 Sdg S Y CZ Z CX X Tdg H SWAP Unitary2qBox U3 U2 U1 CCX } (try running backend.compile_circuit(circuit) first).

I narrowed down the issue to pytket/qiskit/qiskit_convert.py: line 118
self.tkc.add_circbox(cbox, qubits + bits, **condition_kwargs)
this is because adding a Qiskit "Instruction" object maps to a Pytket "Circbox"

Since when the converted Pytket circuit is being verified: pytket/backends/backends.py: Backend._check_all_circuits

against the list of required_predicates : [GateSetPredicate:{ Unitary1qBox Measure noop T CU1 Sdg S Y CZ Z CX X Tdg H SWAP Unitary2qBox U3 U2 U1 CCX }]. "Circbox" is not present, which is why I think the above exception is being thrown.

In addition, I verified this by replacing the circuit above with one created just with Pytket:

    from pytket.circuit import Circuit, CircBox
    from pytket.qiskit import qiskit_to_tk
    from pytket.backends.ibm import AerBackend
    boxed_circuit = Circuit(2)

    boxed_circuit.CX(0,1)
    main_circuit = Circuit(2)
    circ_box = CircBox(boxed_circuit)
    main_circuit.H(0)

    main_circuit.add_circbox(circ_box, [0,1])

    main_circuit.measure_all()
    backend = AerBackend()
    backend.compile_circuit(main_circuit)
    result = backend.process_circuits([main_circuit], n_shots=124)
    print(backend.get_counts(result[0]))

which results in the same predicate error as with the first circuit. This is not only for the AerBackend, but also happens with IBMQBackend, which also has a predicate without "Circbox".

A temporary workaround I found was to have pytket/qiskit/qiskit_convert.py: line 118 use Circuit.add_circuit instead of using Circbox. Since this works:

    from pytket.circuit import Circuit, CircBox
    from pytket.qiskit import qiskit_to_tk
    from pytket.backends.ibm import AerBackend
    boxed_circuit = Circuit(2)
    boxed_circuit.CX(0,1)
    main_circuit = Circuit(2)

    main_circuit.H(0)
    main_circuit.add_circuit(boxed_circuit, [0,1])

    main_circuit.measure_all()
    backend = AerBackend()
    backend.compile_circuit(main_circuit)
    result = backend.process_circuits([main_circuit], n_shots=124)
    print(backend.get_counts(result[0]))

However, I assume this is not ideal.

Checking Equality

Given two circuits, how do I check their equality (similar to PyZX's verify_equality)?

Manual build on CI fails

Failure is due to this change in github policy: we can no longer do

python -m pip install --pre git+git://github.com/willsimmons1465/jupyter-sphinx.git@issue-140#egg=jupyter-sphinx

"RuntimeError: Disconnected architecture graph" for some IBMQ backends

I am getting this error when trying to compile some circuits with some IBM backends, this code fails for me:

from pytket.extensions.qiskit import qiskit_to_tk, tk_to_qiskit, IBMQBackend
from pytket.qasm import circuit_from_qasm_str

pytket_backend = IBMQBackend('ibmq_16_melbourne',
                             hub='ibm-q',
                             group='open',
                             project='main',)
pytket_circuit = circuit_from_qasm_str(
    'OPENQASM 2.0;\ninclude "qelib1.inc";\nqreg q[5];\ncreg c[5];\nu3(pi/2,0,pi) q[0];\nu3(pi/2,0,pi)'
    + ' q[1];\ncx q[1],q[0];\nu3(0,0,-pi/4) q[0];\nu3(pi/2,0,pi) q[2];\ncx q[2],q[0];\ncx q[1],q[0];\n'
    + 'u3(0,0,-pi/4) q[0];\nu3(pi/2,0,pi) q[3];\ncx q[3],q[0];\ncx q[1],q[0];\ncx q[2],q[0];\n'
    + 'cx q[1],q[0];\nu3(pi/2,0,pi) q[4];\ncx q[4],q[0];\ncx q[1],q[0];\ncx q[2],q[0];\ncx q[1],q[0];\n'
    + 'cx q[3],q[0];\nu3(0,0,pi/4) q[0];\ncx q[1],q[0];\ncx q[2],q[0];\nu3(0,0,pi/4) q[0];\ncx q[1],q[0];\n'
    + 'cx q[2],q[1];\nu3(0,0,-pi/4) q[1];\ncx q[3],q[1];\ncx q[2],q[1];\ncx q[4],q[0];\ncx q[4],q[1];\n'
    + 'cx q[2],q[1];\ncx q[3],q[1];\nu3(0,0,pi/4) q[1];\ncx q[2],q[1];\ncx q[3],q[2];\nu3(0,0,-pi/4) q[2];\n'
    + 'cx q[4],q[1];\ncx q[4],q[2];\nu3(0,0,pi/4) q[2];\ncx q[3],q[2];\ncx q[4],q[2];\ncx q[4],q[3];\n'
    + 'cx q[4],q[3];\nu3(pi/2,0,pi) q[4];\nbarrier q[0],q[1],q[2],q[3],q[4];\nbarrier q[0];\nbarrier q[1];\n'
    + 'barrier q[2];\nbarrier q[3];\nbarrier q[4];\nmeasure q[0] -> c[0];\nmeasure q[1] -> c[1];\n'
    + 'measure q[2] -> c[2];\nmeasure q[3] -> c[3];\nmeasure q[4] -> c[4];\n'
)
pytket_backend.compile_circuit(pytket_circuit, optimisation_level=2)
tk_to_qiskit(pytket_circuit).draw()

giving an error:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-6-8590b7c732c1> in <module>
     19     + 'measure q[2] -> c[2];\nmeasure q[3] -> c[3];\nmeasure q[4] -> c[4];\n'
     20 )
---> 21 pytket_backend.compile_circuit(pytket_circuit, optimisation_level=2)
     22 tk_to_qiskit(pytket_circuit).draw()

/opt/anaconda3/envs/qiskit0.25.2/lib/python3.8/site-packages/pytket/backends/backend.py in compile_circuit(self, circuit, optimisation_level)
    141         :type optimisation_level: int, optional
    142         """
--> 143         self.default_compilation_pass(optimisation_level).apply(circuit)
    144 
    145     @property

RuntimeError: Disconnected architecture graph

Whereas if I try and run the same with ibmq_santiago rather than ibmq_16_melbourne it will work fine.

I have pytket v0.9.0 and pytket-qiskit v0.9.1 installed through pip.

Can't use pytket-cirq or pytket-qiskit

System version:

Distributor ID:	Ubuntu
Description:	Ubuntu 18.04.4 LTS
Release:	18.04
Codename:	bionic
pip: 20.0.2
python: 3.7.5

To reproduce the problem:

pip install pytket pytket-cirq pytket-qiskit
python
>>>import pytket
>>>pytket.cirq.cirq_to_tk()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'pytket' has no attribute 'cirq'
>>> pytket.qiskit.qiskit_to_tk()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'pytket' has no attribute 'qiskit'

This is following the method given in the documentation: here

I'm not sure how to proceed from here.
Thanks,

new version not available with pip

I noticed on PyPi, 0.5.4 is out. However, I upgraded pip to 20.1, and used pip install pytket==0.5.4. It says

ERROR: Could not find a version that satisfies the requirement pytket==0.5.4 (from versions: 0.0.1, 0.0.2, 0.1.0, 0.1.1, 0.1.2, 0.1.3, 0.1.4, 0.1.5, 0.1.6, 0.2.0, 0.2.1, 0.2.2, 0.2.3, 0.3.0, 0.4.0, 0.4.1, 0.4.2)
ERROR: No matching distribution found for pytket==0.5.4

Installation error

When trying to install, get the following error:

ERROR: Could not find a version that satisfies the requirement qiskit-aqua-chemistry~=0.4.0 (from pytket) (from versions: none) ERROR: No matching distribution found for qiskit-aqua-chemistry~=0.4.0 (from pytket)

Can't open examples_backend.ipynb

After latest update the examples_backend.ipynb notebook fails to open. When launched with binder the following error appears:
Unreadable Notebook: /home/jovyan/examples/backends_example.ipynb NotJSONError('Notebook does not appear to be JSON: '{\n "cells": [\n {\n "cell_type": "m...')

Have also tried copying the raw source code and running local, also fails to read.

RuntimeError when mapping to Aspen

I get a mysterious "RuntimeError: 4" error when I try to map a certain 16-qubit CNOT circuit to the Rigetti 16Q-Aspen architecture. This seems to only happen for some circuits, so I suspect its some sort of funny edge case.

I've attached a minimal example, with the crashing circuit (Original0.qasm) and a very similar working circuit (Original1.qasm).

tket-error.zip

LinePlacement and GraphPlacement do not accept FullyConnected.

When using pytket 0.19.2, pytket.routing.GraphPlacement and pytket.routing.LinePlacement do not accept an instance of pytket.routing.FullyConnected as a constructor argument. This problem does not occur when using pytket 0.17.0.

Example of an error message:

TypeError: __init__(): incompatible constructor arguments. The following argument types are supported:
    1. pytket._tket.routing.GraphPlacement(arc: pytket._tket.routing.Architecture)

Invoked with: <tket::FullyConnected, nodes=10>

Math display errors in circuit_generation_example.ipynb

Hi 👋

I was having a look at the notebook circuit_generation_example.ipynb (https://github.com/CQCL/pytket/blob/master/examples/circuit_generation_example.ipynb) and I found two minor math display errors in two equations. In details:

  1. line 357: there is a \\frac12 instead of \\frac{1}{2}, which outputs an erroneous Rz rotation with a "-12/i" instead of "-1/2 * i";
  2. line 579: same as before, \\frac12 instead of \\frac{1}{2}, which creates some problem with the brackets in the equation.

Didn't know if opening a PR would be the best thing to do in this case for you, so I opened an issue. Hope that's fine 😅

🙂

Expand NumPy version compatibility

pytket currently requires numpy~=1.20. Unfortunately TensorFlow is stuck at numpy<1.20, and looks as though it will be for a while (Google and TensorFlow are very large beasts to move), so pytket and TensorFlow are incompatible for the foreseeable future.

Is there any chance pytket could relax its numpy requirement to >=1.19,<1.21?

Number of shots error for basic AER example

When trying to run the simplest example from ReadTheDocs

from pytket import Circuit
c = Circuit(2,2) # define a circuit with 2 qubits and 2 bits
c.H(0) # add a Hadamard gate to qubit 0
c.Rz(0.25, 0) # add an Rz gate of angle 0.25*pi to qubit 0
c.CX(1,0) # add a CX gate with control qubit 1 and target qubit 0
c.measure_all() # measure qubits 0 and 1, recording the results in bits 0 and 1

from pytket.extensions.qiskit import AerBackend
b = AerBackend() # connect to the backend
b.compile_circuit(c) # compile the circuit to satisfy the backend's requirements
handle = b.process_circuit(c, 100) # submit the job to run the circuit 100 times
counts = b.get_counts(handle) # retrieve and summarise the results
print(counts)

I'm getting an error from qiskit

ValueError: Parameter n_shots is required for this backend for this backend.

I'm using the latest version of pytket and pytket-qiskit with Python 3.7.4.

Complete error message

ValueError Traceback (most recent call last)
in
3 b.compile_circuit(c) # compile the circuit to satisfy the backend's requirements
4 handle = b.process_circuit(c, 100) # submit the job to run the circuit 100 times
----> 5 counts = b.get_counts(handle) # retrieve and summarise the results
6 print(counts)

c:\users\jhs4\appdata\local\continuum\anaconda3\envs\pytket\lib\site-packages\pytket\backends\backend.py in get_counts(self, circuit, n_shots, basis, valid_check, **kwargs)
398
399 result, _ = self._process(
--> 400 circuit, n_shots=n_shots, valid_check=valid_check, **kwargs
401 )
402 c_bits = (

c:\users\jhs4\appdata\local\continuum\anaconda3\envs\pytket\lib\site-packages\pytket\backends\backend.py in _process(self, circuit, **kwargs)
302 self, circuit: Circuit, **kwargs: KwargTypes
303 ) -> Tuple[BackendResult, ResultHandle]:
--> 304 handle = self.process_circuit(circuit, **kwargs) # type: ignore
305 result = self.get_result(handle, **kwargs)
306 self.pop_result(handle)

c:\users\jhs4\appdata\local\continuum\anaconda3\envs\pytket\lib\site-packages\pytket\backends\backend.py in process_circuit(self, circuit, n_shots, valid_check, **kwargs)
185
186 return self.process_circuits(
--> 187 [circuit], n_shots=n_shots, valid_check=valid_check, **kwargs
188 )[0]
189

c:\users\jhs4\appdata\local\continuum\anaconda3\envs\pytket\lib\site-packages\pytket\extensions\qiskit\backends\aer.py in process_circuits(self, circuits, n_shots, valid_check, **kwargs)
449 if n_shots is None or n_shots < 1:
450 raise ValueError(
--> 451 "Parameter n_shots is required for this backend for this backend."
452 )
453 return super().process_circuits(circuits, n_shots, valid_check, **kwargs)

ValueError: Parameter n_shots is required for this backend for this backend.

_.transform module not found

Scenario:
from pytket._transform import Transform

Error: ModuleNotFoundError: No module named 'pytket._transform'

pytket-pyzx should convert phases to Fraction

The method pytket.pyzx.tk_to_pyzx converts phases in gates like Z and X rotations to floating points, instead of to Fraction instances. This is a problem for instance for V gates, which get converted to XPhase(0.5) gates, while it should be converted to XPhase(Fraction(1,2)). I'm actually kind of surprised PyZX didn't raise an exception for this.

Upgrading from 0.61 to 0.71 numpy error

I ran pip install pytket pytket_qiskit pytket_cirq -U

I then fixed some import paths to be consistent with 0.71

The running a simple program to print a circuit ended in a stack trace

Traceback (most recent call last):
File "/home/krehermann/git/oreilly-qc.github.io/samples/Pytket/ch03_02_entangled_aubits.py", line 2, in
from pytket.backends.ibm import AerStateBackend, AerBackend
ModuleNotFoundError: No module named 'pytket.backends.ibm'
(qc-3.7) (base) krehermann@krehermann-Blade:~/git/oreilly-qc.github.io$ /home/krehermann/.virtualenvs/qc-3.7/bin/python /home/krehermann/git/oreilly-qc.github.io/samples/Pytket/ch03_02_entangled_aubits.py
Traceback (most recent call last):
File "/home/krehermann/git/oreilly-qc.github.io/samples/Pytket/ch03_02_entangled_aubits.py", line 2, in
from pytket.extensions.backends.ibm import AerStateBackend, AerBackend
File "/home/krehermann/.virtualenvs/qc-3.7/lib/python3.7/site-packages/pytket/extensions/backends/ibm/init.py", line 12, in
from .ibm import IBMQBackend, NoIBMQAccountError
File "/home/krehermann/.virtualenvs/qc-3.7/lib/python3.7/site-packages/pytket/extensions/backends/ibm/ibm.py", line 15, in
import qiskit # type: ignore
File "/home/krehermann/.virtualenvs/qc-3.7/lib/python3.7/site-packages/qiskit/init.py", line 57, in
from qiskit.providers.aer import Aer
File "/home/krehermann/.virtualenvs/qc-3.7/lib/python3.7/site-packages/qiskit/providers/aer/init.py", line 64, in
from .aerprovider import AerProvider
File "/home/krehermann/.virtualenvs/qc-3.7/lib/python3.7/site-packages/qiskit/providers/aer/aerprovider.py", line 20, in
from .backends.qasm_simulator import QasmSimulator
File "/home/krehermann/.virtualenvs/qc-3.7/lib/python3.7/site-packages/qiskit/providers/aer/backends/init.py", line 20, in
from .pulse_simulator import PulseSimulator
File "/home/krehermann/.virtualenvs/qc-3.7/lib/python3.7/site-packages/qiskit/providers/aer/backends/pulse_simulator.py", line 26, in
from ..pulse.controllers.pulse_controller import pulse_controller
File "/home/krehermann/.virtualenvs/qc-3.7/lib/python3.7/site-packages/qiskit/providers/aer/pulse/init.py", line 52, in
from .system_models.duffing_model_generators import duffing_system_model
File "/home/krehermann/.virtualenvs/qc-3.7/lib/python3.7/site-packages/qiskit/providers/aer/pulse/system_models/duffing_model_generators.py", line 21, in
from .hamiltonian_model import HamiltonianModel
File "/home/krehermann/.virtualenvs/qc-3.7/lib/python3.7/site-packages/qiskit/providers/aer/pulse/system_models/hamiltonian_model.py", line 22, in
from .string_model_parser.string_model_parser import HamiltonianParser
File "/home/krehermann/.virtualenvs/qc-3.7/lib/python3.7/site-packages/qiskit/providers/aer/pulse/system_models/string_model_parser/string_model_parser.py", line 23, in
from .qobj_from_string import gen_oper
File "/home/krehermann/.virtualenvs/qc-3.7/lib/python3.7/site-packages/qiskit/providers/aer/pulse/system_models/string_model_parser/qobj_from_string.py", line 18, in
from ...qutip_extra_lite import qobj_generators
File "/home/krehermann/.virtualenvs/qc-3.7/lib/python3.7/site-packages/qiskit/providers/aer/pulse/qutip_extra_lite/qobj_generators.py", line 19, in
from . import operators as ops
File "/home/krehermann/.virtualenvs/qc-3.7/lib/python3.7/site-packages/qiskit/providers/aer/pulse/qutip_extra_lite/operators.py", line 56, in
from .fastsparse import fast_csr_matrix, fast_identity
File "/home/krehermann/.virtualenvs/qc-3.7/lib/python3.7/site-packages/qiskit/providers/aer/pulse/qutip_extra_lite/fastsparse.py", line 440, in
from .cy.spmath import (zcsr_transpose, zcsr_adjoint, zcsr_mult)
File "spmath.pyx", line 1, in init qiskit.providers.aer.pulse.qutip_extra_lite.cy.spmath

Manually upgrading numpy pip install numpy -U fixed the issue (upgrading from 1.19 to 1.20)

I'm not a pip expert, but it seems to me that the pip install pytket* -U ought to have resolved this dependency.

New pip dependency resolver is wreaking havok

I'm trying to install cirq 0.9.1 and pytket, which should work in theory. The details of my tribulations are here: quantumlib/ReCirq#104

In summary: since the latest version of pytket wants cirq ~= 0.8.0 and I specifically ask for cirq 0.9.1, the dependency resolver goes hunting for something that will work and it sees that pytket-cirq 0.3 has a specification that is looser: it requires cirq ~= 0.6 (note the lack of third decimal). It mixes-and-matches pytket-cirq 0.3 with pytket 0.6.1 which results in disaster.

Suggestions:

  • looser pin to cirq. We'll try not to break anything :)
  • the pytket <--> pytket-cirq pinning should be stronger
  • If you don't want to loosen the pin to cirq, please allow cirq 0.9.x which works fine

RuntimeError: Not enough qubits in circuit to make given placement connected

I tried to route a QUEKO benchmark circuit on a customized device architecture (works on IBM rochester originally) and got the following error message:

Traceback (most recent call last):
  File "main.py", line 124, in <module>
    passes.apply(unit)
RuntimeError: Not enough qubits in circuit to make given placement connected

I just make sure the customized device architecture is connected and AFAIK a larger architecture can accommodate smaller circuits, so I have know idea what the "not enough qubits in circuit" means :(

My code is here for reference:
https://github.com/darkbtf/tket-quantum-circuit-routing

can not find dll

import pytket
Traceback (most recent call last):
File "", line 1, in
File "E:\python\python37\lib\site-packages\pytket_init_.py", line 11, in
from pytket.circuit import ( # type: ignore
File "E:\python\python37\lib\site-packages\pytket\circuit_init_.py", line 14, in
from pytket._tket.circuit import * # type: ignore
ImportError: DLL load failed: 找不到指定的模块。

Unable to get started

I have recently tried to install pytket on a Windows 10 Enterprise LTSC machine and am unable to use the package from the get-go. I am using Python 3.7.9 and use the command pip install pytket==0.6.1. The installation works but when I load up a python console and try to import pytket, it fails with the following message:

Python 3.7.9 (tags/v3.7.9:13c94747c7, Aug 17 2020, 18:58:18) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pytket
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\QC\Envs\pyqt\lib\site-packages\pytket\__init__.py", line 18, in <module>
    from pytket.circuit import (
  File "C:\Users\QC\Envs\pyqt\lib\site-packages\pytket\circuit\__init__.py", line 17, in <module>
    from pytket._tket.pauli import Pauli
ImportError: DLL load failed: The specified module could not be found.

I have looked in the _tket folder on this machine and the files that need to be there do appear to be there as they match the filenames for an install of pytket I have on another machine with the same version of python and pytket that works. The computer with the functioning installation has just Enterprise instead of Enterprise LTSC. I've gone as far as making a requirements file out of a pip freeze from a functioning virtual environment on the functioning machine and using that to set up an environment on the failing machine for the project I'm working on as well as only having pytket installed. Failure happens in each case.

EDIT: Problem also seems to exist on Python 3.8.2 for the same machine.

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.