Пример #1
0
def run_blackbird_script(args):
    """Run a blackbird script.

    Related arguments:
    * input: the input blackbird script to be run
    * output: the output file to store the results in (optional)

    Args:
        args (ArgumentParser): arguments that were specified on the command
            line stored as attributes in an argument parser object
    """
    try:
        program = load(args.input)
    except FileNotFoundError:
        sys.stdout.write("The {} blackbird script was not found.".format(
            args.input))
        sys.exit()

    eng = RemoteEngine(program.target)

    sys.stdout.write("Executing program on remote hardware...\n")
    result = eng.run(program)

    if result and result.samples is not None:
        write_script_results(result.samples, output_file=args.output)
    else:
        sys.stdout.write(
            "Ooops! Something went wrong with obtaining the results. Please check the Blackbird script specified and the connection to the remote engine."
        )
        sys.exit()
Пример #2
0
    def test_run(self, prog):
        """Tests that a blocking job execution can succeed."""
        engine = RemoteEngine("X8_01")
        result = engine.run(prog, shots=10)

        assert result is not None
        assert np.array_equal(result.samples, [[1, 2], [3, 4]])

        result.state is None
    def test_run_complete(self, connection, prog, job_to_complete):
        """Tests a successful blocking job execution."""
        engine = RemoteEngine("X8_01", connection=connection)
        result = engine.run(prog, shots=10)

        assert np.array_equal(result.samples, np.array([[1, 2], [3, 4]]))

        with pytest.raises(
            AttributeError, match="The state is undefined for a stateless computation."
        ):
            result.state