GithubHelp home page GithubHelp logo

jwoehr / qisjob Goto Github PK

View Code? Open in Web Editor NEW
32.0 4.0 4.0 583 KB

Qiskit Job Control

License: Other

Python 92.01% Makefile 1.13% OpenQASM 5.31% Pascal 1.55%
quantum-computing qiskit python3 qasm

qisjob's Introduction

qisjob

Qiskit Job Control

The qisjob module

The module is qisjob. It was formerly named qis_job. I'm not sure why, but I have now changed it to qisjob.

If you previously installed the module as qis_job you can uninstall that older version either by

  • pip3 uninstall qis_job
  • make uninstall_oldname

The qisjob command

The qisjob command loads and executes Qiskit experiments on simulators or on genuine quantum computing hardware such as that found at IBM Q Experience. Input is from one or more OpenQASM 2 (by default) or OpenQASM 3 (with the --qasm3_in option) source files or Qiskit QuantumCircuit Python code (with the --qc option) or from source provided via standard input in the absence of file arguments.

The command also provides some utility functions such as:

  • enumerating backend platforms
  • configuration both current and historical of backend platforms
  • status of backend platforms
  • status and results of jobs both current and historical

and other useful operations for Qiskit experimentation.

qisjob comes with NO GUARANTEE and NO WARRANTY including as regards correctness nor applicability. See LICENSE.

qisjob can run Qiskit experiments expressed as either:

  • OPENQASM Open Quantum Assembly Language
  • Qiskit Terra QuantumCircuit Python code snippet.
    • To use a code snippet, only import that which is absolutely needed in the snippet and provide no execution code.
    • Pass the name of your QuantumCircuit to the --qc argument of qisjob.py
      • If you have multiple files of this sort, all must have the same name for their QuantumCircuit object.
      • An example circuit (very long execution!) is found in the qc_examples subdirectory of the project.

You can load and run multiple files, but you cannot mix Qasm and QuantumCircuit files in the same execution of the qisjob.

QisJob is compatible with the experimental NuQasm2 project, that you can use to compile and run your OPENQASM2.0 source code. Given that you have NuQasm2 installed, you can use qisjob's -n include-path:include-path:... switch

The QisJob class

The qisjob script works by instancing an object of the class qisjob.QisJob.

You can use an object instance of the class qisjob.QisJob in your own program for its utility functions or the execute experiments on real quantum hardware and/or simulators either using OpenQASM source or Qiskit QuantumCircuit source code.

QisJob Documentation

The qisjob.QisJob object that underlies the qisjob script that can be used in your own programs has many args/kwargs.

The documentation for qisjob.QisJob is installed with the module in the site library's share/doc.

You can also read the QisJob Documentation Online

Prerequisites

Install

Do one of the following in the source directory (preferably in a Python virtual environment set up for Qiskit)

  • make # gnu make, we have provided a Makefile
  • ./setup.py install
  • pip3 install .

Note that the module name has recently (2021-02-16) changed from qis_job to qisjob. If you previously installed the module as qis_job you can uninstall that older version either by

  • pip3 uninstall qis_job
  • make uninstall_oldname

Uninstall

Do one of the following in the source directory

  • make uninstall
  • pip3 uninstall qisjob

Usage

The qisjob script has helpful help.

$ qisjob --help
usage: qisjob [-h] [-i | -s | -a | -b BACKEND]
              [--qasm_simulator | --unitary_simulator | --statevector_simulator | --pulse_simulator | --densitymatrix_simulator]
              [--statevector_gpu | --unitary_gpu | --density_matrix_gpu] [--fakenoise FAKENOISE] [--display] [--version]
              [--api_provider API_PROVIDER] [--hub HUB] [--group GROUP] [--project PROJECT] [--providers] [--qvm] [--qvm_as] [--backends] [-1]
              [-d DATETIME] [-g] [-j] [--jobs JOBS] [--job_id JOB_ID] [--job_result JOB_RESULT] [-m] [-n NUQASM2] [-o OUTFILE] [-p] [-q QUBITS]
              [--qiskit_version] [-r] [-t SHOTS] [-v] [-x] [--showsched] [--circuit_layout] [--optimization_level OPTIMIZATION_LEVEL]
              [--histogram] [--plot_state_city PLOT_STATE_CITY] [--figure_basename FIGURE_BASENAME] [--qasm] [--qc QC] [--status]
              [--token TOKEN] [--url URL] [--use_job_monitor] [--job_monitor_line JOB_MONITOR_LINE]
              [--job_monitor_filepath JOB_MONITOR_FILEPATH] [-w] [--qasm3_in] [--qasm3_out]
              [filepath ...]

Qisjob loads from one or more OpenQASM source files or from a file containing a Qiskit QuantumCircuit definition in Python and runs as
experiments with reporting in CSV form. Can graph results as histogram or state-city plot. Also can give info on backend properties, qiskit
version, show circuit transpilation, etc. Can run as multiple jobs or all as one job. Exits 0 on success, 1 on argument error, 100 on runtime
error, 200 on QiskitError. Copyright 2019, 2023 Jack Woehr [email protected] PO Box 82, Beulah, Colorado 81023. Apache License, Version 2.0
-- See LICENSE which you should have received with this code. Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
for the specific language governing permissions and limitations under the License.

positional arguments:
  filepath              Filepath(s) to 0 or more .qasm files, default is stdin

options:
  -h, --help            show this help message and exit
  -i, --ibmq            Use best genuine IBMQ processor (default)
  -s, --sim             Use IBMQ qasm simulator
  -a, --aer             Use QISKit Aer simulator. Default is Aer simulator. Use -a --qasm-simulator to get Aer qasm simulator. Use -a --unitary-
                        simulator to get Aer unitary simulator.
  -b BACKEND, --backend BACKEND
                        Use specified IBMQ backend
  --qasm_simulator      With -a use qasm_simulator instead of aer simulator
  --unitary_simulator   With -a use unitary_simulator instead of aer simulator
  --statevector_simulator
                        With -a use aer_simulator_statevector instead of aer simulator
  --pulse_simulator     With -a use pulse_simulator instead of aer simulator
  --densitymatrix_simulator
                        With -a use aer_simulator_density_matrix instead of aer simulator
  --statevector_gpu     With -a and --qasm_simulator use gpu statevector simulator
  --unitary_gpu         With -a and --qasm_simulator use gpu unitary simulator
  --density_matrix_gpu  With -a and --qasm_simulator use gpu density matrix simulator
  --fakenoise FAKENOISE
                        Uses IBM/fake backend to simulate noise in the circuit with -a use --fakenoise ibmq_lima/ --fakenoise FakeVigo
  --display             Uses circuit.draw to visualize the untranspiled circuit
  --version             Announce QisJob version
  --api_provider API_PROVIDER
                        Backend remote api provider, currently supported are [IBMQ | Forest | MQT | QI]. Default is IBMQ.
  --hub HUB             Provider hub, default is 'ibm-q'
  --group GROUP         Provider group, default is 'open'
  --project PROJECT     Provider project, default is 'main'
  --providers           List hub/group/project providers for IBMQ
  --qvm                 Use Forest local qvm simulator described by -b backend, generally one of qasm_simulator or statevector_simulator. Use
                        --qvm_as to instruct the simulator to emulate a specific Rigetti QPU
  --qvm_as              Use Forest local qvm simulator to emulate the specific Rigetti QPU described by -b backend. Use --qvm to run the Forest
                        local qvm simulator described by -b backend.
  --backends            Print list of backends to stdout and exit 0
  -1, --one_job         Run all experiments as one job
  -d DATETIME, --datetime DATETIME
                        Datetime 'year,month,day[,hour,min,sec]' for -p,--properties
  -g, --configuration   Print configuration for backend specified by -b to stdout and exit 0
  -j, --job             Print your job's dictionary
  --jobs JOBS           Print JOBS number of jobs and status for -b backend and exit 0
  --job_id JOB_ID       Print job number JOB_ID for -b backend and exit 0
  --job_result JOB_RESULT
                        "Print result of job number JOB_RESULT for -b backend and exit 0
  -m, --memory          Print individual results of multishot experiment
  -n NUQASM2, --nuqasm2 NUQASM2
                        "Use nuqasm2 to translate OPENQASM2 source, providing include path for any include directives
  -o OUTFILE, --outfile OUTFILE
                        Write appending CSV to outfile, default is stdout
  -p, --properties      Print properties for backend specified by -b to stdout and exit 0
  -q QUBITS, --qubits QUBITS
                        Number of qubits for the experiment, default is 5
  --qiskit_version      Print Qiskit version and exit 0
  -r, --result          Print job result
  -t SHOTS, --shots SHOTS
                        Number of shots for the experiment, default 1024, max 8192
  -v, --verbose         Increase runtime verbosity each -v up to 3. If precisely 4, prettyprint QisJob's data dictionary and return (good for
                        debugging script arguments)
  -x, --transpile       Print circuit transpiled for chosen backend to stdout before running job
  --showsched           In conjuction with -x, show schedule for transpiled circuit for chosen backend to stdout before running job
  --circuit_layout      With -x, write image file of circuit layout after transpile (see --figure_basename)
  --optimization_level OPTIMIZATION_LEVEL
                        Set optimization level for transpilation before run, valid values 0-3, default is 1
  --histogram           Write image file of histogram of experiment results (see --figure_basename)
  --plot_state_city PLOT_STATE_CITY
                        Write image file of state city plot of statevector to PLOT_STATE_CITY decimal points (see --figure_basename)
  --figure_basename FIGURE_BASENAME
                        basename including path (if any) for figure output, default='figout', backend name, figure type, and timestamp will be
                        appended
  --qasm                Print qasm file to stdout before running job
  --qc QC               Indicate variable name of Python-coded QuantumCircuit
  --status              Print status of chosen --backend to stdout (default all backends) of --api_provider (default IBMQ) and exit 0
  --token TOKEN         Use this token
  --url URL             Use this url
  --use_job_monitor     Display job monitor instead of just waiting for job result
  --job_monitor_line JOB_MONITOR_LINE
                        Comma-separated list of hex values for character(s) to emit at the head of each line of job monitor output, default is
                        '0x0d'
  --job_monitor_filepath JOB_MONITOR_FILEPATH
                        Filepath for Job Monitor output if Job Monitor requested by --use_job_monitor, default is sys.stdout
  -w, --warnings        Don't print warnings on missing optional modules
  --qasm3_in            Interpret input as OpenQASM 3
  --qasm3_out           Print qasm file as OpenQASM 3 to stdout before running job

Notes

  • It is recommended you download or clone the most recent release.
    • Version v4.1.2 is the current version.
  • This document always reflects the latest checkins and may be ahead of the release versions.
    • See the README.md in the release version itself for contemporary information.
  • Please use the issue tracker to report any issues or feature requests.
  • If Python complains about the certs, you could try setting an env variable, like this:
    • export SSL_CERT_FILE=$(python3 -c "import certifi; print(certifi.where())")

Software Bill of Materials

The Software Bill of Materials (SBOM) is SBOM_qisjob_jwoehr_*.json

Jack Woehr 2023-06-07

qisjob's People

Contributors

dubeypray avatar jwoehr avatar omarcostahamido 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

Watchers

 avatar  avatar  avatar  avatar

qisjob's Issues

Aer qasm_simulator has much lower max number of shots when used via qisjob!

Ok, now I confirmed this.
on the same python environment where I have qisjob installed:

$ python
>>> import time; from qiskit import *
>>> qc = QuantumCircuit(1,1); qc.h(0); qc.measure(0,0)
>>> backend = Aer.get_backend('qasm_simulator')
>>> start_time = time.time(); print( execute(qc, backend, shots=1000000).result().get_counts() ); print("--- %s seconds ---" % (time.time() - start_time));

has no problem running.
However this will not run:
$ qisjob onebit.qasm -a --qasm_simulator -t 200000

(you can assume that I am inside the share/qasm_examples folder here)
It will throw:

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/_bootstrap.py:219: UserWarning: QuantumInspire not installed.
  return f(*args, **kwds)
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/_bootstrap.py:219: UserWarning: Rigetti Forest not installed.
  return f(*args, **kwds)
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/_bootstrap.py:219: UserWarning: qiskit-jku-provider not installed.
  return f(*args, **kwds)
Traceback (most recent call last):
  File "/Users/user/Documents/qis_job/QISJOB/bin/qisjob", line 244, in <module>
    QJ.do_it()
  File "qis_job/qis_job.pyx", line 301, in qis_job.qis_job.QisJob.do_it
  File "qis_job/qis_job.pyx", line 616, in qis_job.qis_job.QisJob.one_exp
  File "/Users/user/Documents/qis_job/QISJOB/lib/python3.7/site-packages/qiskit/execute.py", line 289, in execute
    **run_config)
  File "/Users/user/Documents/qis_job/QISJOB/lib/python3.7/site-packages/qiskit/compiler/assemble.py", line 141, in assemble
    rep_delay, **run_config)
  File "/Users/user/Documents/qis_job/QISJOB/lib/python3.7/site-packages/qiskit/compiler/assemble.py", line 226, in _parse_common_args
    'backend: %s.' % (shots, max_shots))
qiskit.exceptions.QiskitError: 'Number of shots specified: 200000 exceeds max_shots property of the backend: 65536.'

General Refactoring of Code

QisJob "just grew".

It is time to refactor the code so it is easier to maintain and contains less cut-and-paste code reuse.

#22 in some respects is along these lines, though there is other content to that issue.

don't quit python please! ๐Ÿ›‘

beside the using it in the terminal, I am now exploring using qisjob in a python script.
(long story short, I'm trying to find ways to cut on the time spend just loading python, see more on #16 )
It seems that once the do_it() method gets called on any QisJob object, it will quit the python.
For the laymen (such as me self), it's all the sys.exit(some number?) on the qis_job.pyx that need not to be run.

OCH

Request: tutorial

I would like to request a tutorial on how to best use current qis_job.
In particular I would like to understand what is the best workflow to figure out the least busy machines, and how to list just the queue size for each machine.

question: nuqasm required or optional?

The readme reads:

You can use the experimental NuQasm2 to compile your OPENQASM2.0 source code and run it if you first install that project and then use qisjob's -n include-path:include-path:... switch

Is it optional or required to have nuqasm to compile and run qasm from a openqasm file?

supressing warnings?

everytime I qisjob -h I get at the top:

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/_bootstrap.py:219: UserWarning: QuantumInspire not installed.
  return f(*args, **kwds)
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/_bootstrap.py:219: UserWarning: Rigetti Forest not installed.
  return f(*args, **kwds)
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/_bootstrap.py:219: UserWarning: qiskit-jku-provider not installed.
  return f(*args, **kwds)
(...)

would it be possible to suppress it here and only show the warning if I attempt to use any of those backends without the required prerequisite?

cannot read qasm from qasm_src

I was having trouble learning how to use qasm_src kwarg.

Jack wrote some important instructions on slack:

qasm_src is only a kwarg to the QisJob ctor.
If you want to pass source via stdin to the qisjob command, just give no file arg and pipe stdin to the instance

as an example:
echo 'OPENQASM 2.0; include qelib1.inc; qreg q[1]; creg c[1]; h q[0]; measure q[0] -> c[0];' | qisjob -b ibmqx2

Note: qelib1.inc needs to be inside quotes.

Though, this example itself was not enough to make it work since it was throwing the error:
UnboundLocalError: local variable 'the_source' referenced before assignment

Jack found that to be solvable with un-indenting a line.
This fix can now be seen here.

improve qisjob speed ๐Ÿ˜…

dear @jwoehr, I've finished the speed tests of all the possible combinations of software and externals I've been working with (in combination and each on its own) and realized that the ones that involve qisjob are the slowest. I noticed that even just running qisjob on its own, i can never get execution time bellow 1.3 seconds: time qisjob -a --qasm_simulator -t 2000 onebit.qasm . If you think you could have an insight into why this may be, and that you can find a fix for it, I'd be happy to continue testing with a newer versions. Thank you again for this :)

-w not completely working yet

It appears that -w is still not actually getting rid of all warnings.
On the one hand, with new qiskit installation, there are a lot of deprecation warnings that -w gets rids of.
However, on the other hand, the UserWarning: QuantumInspire/forest/jku not installed. are still showing up.

installing... missing instruction?

here is what I am getting:

$  ./setup.py 
Compiling qis_job/qis_job.pyx because it changed.
[1/1] Cythonizing qis_job/qis_job.pyx
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
   or: setup.py --help [cmd1 cmd2 ...]
   or: setup.py --help-commands
   or: setup.py cmd --help

error: no commands supplied

--job_result is broken

qisjob --backend ibm_nairobi --job_result xxxxxxxx raises AttributeError: 'IBMBackend' object has no attribute 'retrieve_job'

Must be BackendV2 fu.

add simple kwarg for noise in simulation

Something my team had done back in the day, was to add a simple interface to add noise when running a job on a full qiskit simulator.
I believe this would go something like:

from qiskit.providers.aer import noise  # import Aer noise models

RealDeviceName='ibmq_rome'
device = IBMQ.get_provider(hub='ibm-q', group='open', project='main').get_backend(RealDeviceName)
properties = device.properties()
coupling_map = device.configuration().coupling_map

# Generate an Aer noise model for device
noise_model = noise.device.basic_device_noise_model(properties)
basis_gates = noise_model.basis_gates

# Perform noisy simulation
backend = Aer.get_backend('qasm_simulator')
job_sim = execute(quantumCircuit, backend,
      coupling_map=coupling_map,
      noise_model=noise_model,
      basis_gates=basis_gates)
result = job_sim.result()

needless to say, I don't want to have to do all of this.
It would be nice to just turn it on with a simple argument --noise

matplotlib dependency?

a simple run of a qasm file returns:

warnings.warn('Timestamps in IBMQ backend properties, jobs, and job results '
Traceback (most recent call last):
  File "/Users/user/Documents/QISJOB/bin/qisjob", line 231, in <module>
    QJ.do_it()
  File "qis_job/qis_job.pyx", line 229, in qis_job.qis_job.QisJob.do_it
    self.one_exp(f_path)
  File "qis_job/qis_job.pyx", line 512, in qis_job.qis_job.QisJob.one_exp
    self.verbosity(circ.draw(), 2)
  File "/Users/user/Documents/QISJOB/lib/python3.7/site-packages/qiskit/circuit/quantumcircuit.py", line 1370, in draw
    cregbundle=cregbundle)
  File "/Users/user/Documents/QISJOB/lib/python3.7/site-packages/qiskit/visualization/circuit_visualization.py", line 341, in circuit_drawer
    cregbundle=cregbundle)
  File "/Users/user/Documents/QISJOB/lib/python3.7/site-packages/qiskit/visualization/circuit_visualization.py", line 699, in _matplotlib_circuit_drawer
    cregbundle=cregbundle, global_phase=global_phase)
  File "/Users/user/Documents/QISJOB/lib/python3.7/site-packages/qiskit/visualization/matplotlib.py", line 121, in __init__
    raise ImportError('The class MatplotlibDrawer needs matplotlib. '
ImportError: The class MatplotlibDrawer needs matplotlib. To install, run "pip install matplotlib".

is there an option that I can use to work around this, or is it a mandatory dependency?
I'm trying to find the most lightweight installation/setup for qisjob.

qisjob getting rid of hangs and throwin error instead

title says it all.
I'm not sure I was supposed to have anything in the job list as I've had errors running the simple qasms, but when running qisjob --job it didn't return nor display any useful result besides the usual:

$  qisjob --job
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/_bootstrap.py:219: UserWarning: QuantumInspire not installed.
  return f(*args, **kwds)
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/_bootstrap.py:219: UserWarning: Rigetti Forest not installed.
  return f(*args, **kwds)
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/_bootstrap.py:219: UserWarning: qiskit-jku-provider not installed.
  return f(*args, **kwds)
/Users/user/Documents/QISJOB/lib/python3.7/site-packages/qiskit/providers/ibmq/ibmqfactory.py:192: UserWarning: Timestamps in IBMQ backend properties, jobs, and job results are all now in local time instead of UTC.
  warnings.warn('Timestamps in IBMQ backend properties, jobs, and job results '

qis_job and qisjob

the repo is called qis_job but the command is qisjob.
would it be a good idea to make this consistent and rename the repo to qisjob?

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.